Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In eclipse, maven dependencies are overriding project dependencies

I have a "master project" that uses several "modules". The modules are in the pom.xml, but I also have the code for the modules as projects in Eclipse. I defined the modules as project dependencies both in "Properties|Project References" and in "Properties|Java Build Path". I also made sure all of the Eclipse projects are at the top of "Order and Export" in Java Build Path.

The master project is not recognizing changes to the modules within eclipse. When I press F3 to see the code, it opens java source from my .m2 directory. It's obviously ignoring my Eclipse projects. Am I missing some setting? What should I do?

like image 784
User1 Avatar asked Nov 22 '11 18:11

User1


People also ask

What is Maven dependencies in Eclipse?

It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects. Now, you can add a dependency in pom.xml.

How do dependencies work in Maven?

Dependencies are external JAR files (Java libraries) that your project uses. If the dependencies are not found in the local Maven repository, Maven downloads them from a central Maven repository and puts them in your local repository. The local repository is just a directory on your computer's hard disk.

What is project dependency in Eclipse?

Each project (dependencies, etc.) must be able to be managed from within the Eclipse IDE without manually editing build.xml files. It must be possible for each project to export a build.xml Ant file such that. It can be used to build all appropriate targets from a command line using CVS and Ant.


2 Answers

You don't need to add the dependent projects into the Project references (at least when using m2eclipse-plugin), just add them as dependencies on your masters' pom.xml. I haven't had the need to touch the Build path since I've started using Maven in Eclipse.

Make sure you have enabled the Workspace resolution of the plugin by right clicking on project root -> Maven -> Enable Workspace Resolution. If it says "Disable Workspace Resolution", it is already enabled. You may also need to run "Update project configuration" under the same menu.

This way when you run your master-project from within Eclipse, any changes made to the other projects will be "visible" to the master (and you can actually use hot swap during runtime even on the other projects).

like image 116
esaj Avatar answered Sep 27 '22 16:09

esaj


If you're using Maven, you pretty much want to commit to Maven. Even if you do configure Eclipse with Eclipse-specific dependencies, anytime you update your project configuration using Maven, it will do a complete rewrite of your configuration.

I strongly recommend converting any of your other project build dependencies into Maven-enabled projects that can be used as Maven dependencies.

In your specific case (through using the Maven modules), this means ensuring that each of your modules are imported into Eclipse as m2e-enabled projects. m2e will then automatically wire in the dependencies between modules and other dependent projects.

like image 40
ziesemer Avatar answered Sep 27 '22 16:09

ziesemer