Eclipse - Project Referencing another Project instead of .jar File - java

I have a Java project in eclipse:
Project A contains an Ivy dependency on Project B.
Locally, I checked out and made changes to Project B. I then wanted to test the new functionality from Project B in Project A, so I added Project B as a project dependency of Project A by adding it to the Java Build Path (Java Build Path->Projects->Add...).
I no longer wish to have that dependency on Project A, but simply removing it from the Projects Build Path hasn't worked. With that dependency removed, I would expect that any references to the new local code would result in a syntax error, since those changes have not been incorporated into a new artifact for Ivy to pull in.
How can I remove any references to Project B from Project A? I've tried deleting both projects and re-checking them out and that did not work.

The way to resolve this issue is to:
Close Project B in eclipse.
On Project A run Project-Clean
Resolve Ivy dependencies on Project A
Now the dependencies from Project B should use the Ivy artifact rather than the local changes.

Related

Setup dependent Maven Java projects so changes are pickedup right away without run maven install

I have two Maven Java projects in Eclipse. I added Project B is a dependency in Project A's pom.xml file. Each time a code change is made to Project B, I have to do 'run maven install' on B, and then do a 'maven update project' on A, in order for the changes to appear in A. Is there a better/faster yet proper way to manage this?
I have tried to remove the maven dependency in A's pom.xml and use Eclipse's the project dependency, that result in class not found error when I try to run A.
You can add "Refresh Resources" -> Entire Workspace after completion in your Maven Run Configuration

Building an artifact from a modified maven project with Intellij

i am trying to build an artifact from a modified maven project imported in intellij (v2016.2).
Have managed to:
(1) Import/build a multi module maven project in intellij
(2) Successfully built/run an artifact as a single jar from the project
(3) Modified maven project by writing new classes with extra depedencies (via changing project's structure and adding new maven dependencies*)
(4) Successfully built & run modified project
however, when i try to run an artifact from the modified project (and even if it contains all the dependencies in the jar), it completely ignores all the extra functionality of the modified project (runs exactly as in (2))
What am I missing?
*note: havent touched any poms till now. All the dependencies added using File>Project Structure>Modules>Dependencies>add Library ...
If you don't see any change when running the project it's because you run the the previous build.
"Add Library" won't update your pom.xml. (Add maven dependency... will do)
To fix your maven project, you need to edit the pom.xml by hand to add the new libraries. (section dependencies)
Once it's done run mvn clean build from command line or from the maven project window (on the right edge of IntelliJ window).

Broken maven dependency while closing the project

I am facing an issue with maven.
I created a project A, build it and did maven install. I see the jar file copied in local repo.
I included the project A's POM dependency in Project B. Project B is now able to reference the project A. The concern here is in eclipse when I expand Maven dependencies in Project explorer it shows me reference to project A instead of jar.
Now when I close project A in workspace of eclipse, the project B could not reference the project A.
Could you please help me understanding and fixing this issue.
Regards,
Amandeep
The M2E plugin in Eclipse is able to see whether a workspace project already satisfies a dependency in another project. You observed it already. If the project is not in the workspace, the dependency will be served by the local and/or the remote repository.
If you close a dependency project, you first have to make a Maven Update. Simply rightclick your project, select "Maven", then "Update". This will recalculate the project settings and its dependencies.

How to share code between two projects?

I have two Java projects called A and B. Both of them are web apps deployed as war files. I created them in Eclipse workspace separately. Project B uses a class in project A named MusicMapper. I added the project A to project B's build path in Eclipse as suggested in this post. So now project B can compile without any errors and the class MusicMapper can be seen in project B by importing it in project B:
import com.projectA.MusicMapper;
Everything seems to be fine before I launched the web app of project B. However, when I launched the project B and called the code that references class MusicMapper in project A, I got the following runtime error:
java.lang.ClassNotFoundException: com.projectA.MusicMapper
So this error seems to be caused by unfound class com.projectA.MusicMapper which is imported from project A. Since I already added project A to project B build path and project B compiles fine without any errors, why does it report this error at runtime?
Another approach I took was: I've also tried using the following Maven import in project B's pom.xml:
<dependency>
<groupId>com.projectA</groupId>
<artifactId>projectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>/path/to/projectA.jar</systemPath>
</dependency>
where projectA.jar is the jar file I exported from project A. But it still gave me the same ClassNotFoundException. How can I make the class in project A usable by project B? It seems that neither of the two approaches I've tried works.
First of all if you have two projects which are both deployed as wars it's not a good idea to include one project into another as a dependency. Because you will be puling in lot of other stuff that you don't need in project B.
A better approach will be to create a Third java project lets say "Common" this should be just a java project and NOT a Dynamic Web Project and should compile as a jar. Move all the stuff that is shared between Project A and Project B into Common project.
Now back your problem Just adding some thing in project build path in eclipse does not mean you have added the dependency to your project outside of eclipse as well. Eclipse don't complain because it can resolve and find the project because you added in eclipse build path. You will have to compile common dependency project using some build tool like ant, maven or gradle and package the jar in your war file when war is built.
If you don't want to use a build tool a simple route would be just export the third project from eclipse as jar. Copy the common jar file in WEB-INF/lib folder of your Project A and Project B before you export the war file from your eclipse.
I hope it helps :)

How to build Maven dependencies without a parent project in NetBeans

I'm using NetBeans 7.4 RC1 to create Maven projects.
Let's say I create two Maven projects, named A and B, and a third named X which includes the other two projects as dependencies.
On building X Maven searches the local Maven repository (and the connected company-proxy) for the dependencies and obviously does not find any initially.
If I run the build command of NetBeans on projects A and B, it performs a maven install, which then installs the projects into my local repository. Now, when I build X it will find the dependency and all is well.
Is there a way to configure Maven (or NetBeans) to automatically build the dependencies (and install it to my local repository)? I know there's a solution to do this with POM Projects (Reactor POM) where the modules (in this case A, B and X I suppose) can be added to it, and the POM project specified as a parent in all the modules - this will allow me to select the "Build with Dependencies" option, which will then build all the modules in the POM project. But this is not a good solution if say project A is a utility project, used in many other projects.
Essentially what I'd like to avoid is building all the dependencies for a project every time I want to test my project; especially when I'm working on the project and its dependencies at the same time.
The key is to try and to this in NetBeans itself, and without modules, if it's possible.
I hope I'm missing the point.
With Compile on Save turned on, Netbeans will attempt to link the opened projects together no matter what reactor they belong to. However this will not build the projects (eg. doesn't create an updated jar file in local repository), just link the current project's maven build to the target/classes of these projects.

Categories