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?
You also need to make sure that you are running the correct goals.
If you don't run the install goal then it won't be copied to your repository and won't compile.
To learn more about goals have a look at https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
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.The correct way to do this is the following:
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.
When eclipse is messed up with importing and deleting several projects, you may need to rebuild index of maven repositories. Here is a way that I have done.
Check if an referenced project is recognized as a maven project by eclipse properly.
In menu bar, click
Window -> Show View -> Other...
When 'Show View' window pops up, select
Maven -> Maven Repositories
In Maven Repositories window, You should see your project as jar file in
Local Repositories -> Workspace Projects
If you can not find your project in
Workspace Projects
, right click onWorkspace Projects
and selectRebuild Index
.Update maven of an referencing project
Right click on the referencing project,
Maven -> Update Project... -> OK