In Eclipse m2e, how to reference workspace project?
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.
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, selectMaven -> Maven Repositories
In Maven Repositories window, You should see your project as jar file inLocal Repositories -> Workspace Projects
If you can not find your project inWorkspace Projects
, right click onWorkspace Projects
and selectRebuild Index
.Update maven of an referencing project
Right click on the referencing project,
Maven -> Update Project... -> OK
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
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.