I use Apache Maven to manage my Java libs (jar) and some of projects that use the libs. For convinience, I use mvn eclipse:eclipse to generate Eclipse project files which can be imported into Eclipse workspace for editing.
Problems arise when I edit the main project and Java lib projects in the same Eclipse workspace. That is, mvn eclipse:eclipse includes src path dependency in .classpath file, not the jar dependency as expected.
Say I have a Jave lib project named mylib. The corresponding jar file mylib.jar has been deployed to a private Maven repo maintained by me. In order to use mylib.jar in the main project, the following dependency is included in pom.xml.
<!-- pom.xml for the main project -->
<dependency>
<groupId>namespace.my</groupId>
<artifactId>mylib</artifactId>
<version>[1.0, )</version>
</dependency>
mvn compile and mvn test work perfect, in which mylib.jar is automatically downloaded from my repo. However, when trying mvn eclipse:eclipse, I find the generated .classpath file doesn’t include mylib.jar dependency as expected. Instead, it includes source file directory for mylib as follows.
<!-- .classpath file generated by mvn eclipse:eclipse -->
<classpathentry kind="src" path="/mylib"/>
It seems that Maven reads Eclipse’s metadata and finds mylib and the main project coexits in the same workspace. Therefore maven includes the source for my good. Damn. How can I tell maven to ignore the local project source and just include the jar file?
I believe this is actually because they’re related projects in Eclipse. So if you right-click on your main project and go to
Project Referencesyour lib project should be ticked.If you run
mvn eclipse:eclipseit will automatically add project references for any sub-projects (modules). You can change this with the useProjectReferences property of the maven eclipse plugin.It defaults to
true, butTo use the property either set the property in your pom.xml
Or as a property on the command line: