Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Eclipse m2e, how to reference workspace project?

How can I reference another workspace project using Eclipse m2e?

Do I have to add a project dependency in the project setting? But in that case the dependency is not shown in the pom.

If I set them in the pom, it will not reference the project in workspace but reference the jar in the local repository. Quite annoying, anyone can help?

like image 469
Wudong Avatar asked May 21 '12 15:05

Wudong


People also ask

What is Maven workspace resolution?

If workspace resolution is disabled, the Maven build for project-a will only succeed if project-b 's artifact is present in the local repository. If workspace resolution is enabled, Maven will resolve the dependency via the MyEclipse workspace.


2 Answers

The correct way to do this is the following:

  • Use the dependencies section in the POM file exclusively, don't fiddle with the Eclipse project references. Right-click the project, then select Maven > Update Project Configuration to reset the project to the Maven default settings. This way, m2e has ownership of the dependencies.
  • Make sure all referenced projects are open in Eclipse and have the Maven nature enabled.
  • Check the Maven settings for each project, make sure that groupId, artifactId and version match with the projects you have open in Eclipse. So if the project you depend on has version 1.0.0-SNAPSHOT in Eclipse, make sure that the depending project's POM file references version 1.0.0-SNAPSHOT in the dependencies section.
  • Enable Workspace Resolution for each of the projects. Right-click the project, then Maven > Enable Workspace Resolution.
  • Finally, if the projects are still not resolved, right-click the project again, then Maven > Update Project

This should solve your problem. If after this, your dependencies are still referenced from the file system, check the groupId, artifactId and especially version of each dependency again.

Also check if you don't have any errors in your project - try to run Maven install.

like image 114
nwinkler Avatar answered Sep 20 '22 06:09

nwinkler


I'd go even further than this. If you've ever run mvn eclipse:eclipse on your project then you're probably in trouble. I had a situation where I had both a "Referenced Libraries" section and a "Maven Dependencies" section in my eclipse project, with conflicting library versions, causing eclipse and myself inevitable confusion.

The safest thing I found was to run mvn eclipse:clean from the command line then go back in to eclipse, refresh the project, "OK" the resulting problem dialog, and then go Maven > Update Project. This sorted it all out for me.

like image 44
Huw Roberts Avatar answered Sep 20 '22 06:09

Huw Roberts