m2eclipse - child projects suddenly cant see each other
Not a very good title, I'll try and explain.
This has worked for months, then today for some unknown reason, eclipse cant resolve any of the imports from siblings (peer projects), when nothing has changed (really!). No eclipse or eclipse plugin updates, no source code changes, no config changes.
I have a fairly standard project structure:
parent_project -- clild_project_a ---- pom.xml -- clild_project_b ---- pom.xml -- child_project_c ---- pom.xml -- pom.xml (for parent).
Now both project a and b are dependent on the code from c.
project a pom.xml.
<parent>
<artifactId>parent_project</artifactId>
<groupId>com.mydomain.ge</groupId>
<version&开发者_如何学JAVAgt;0.0.1-SNAPSHOT</version>
</parent>
...
<dependencies>
<dependency>
<groupId>com.mydomain.ge</groupId>
<artifactId>child_project_c</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
and in the parent pom.xml:
<modules>
<module>child_project_a</module>
<module>child_project_b</module>
<module>child_project_c</module>
</modules>
So now in Eclipse, all the import statements in say project A importing from project c:
package com.skillkash.ge.api;
import com.skillkash.ge.dao.AlreadyExistsException;
This gives:
The import com.skillkash.ge.dao.AlreadyExistsException cannot be resolved.
I tried the follwing:
- doing a maven clean (using right click->run as-> maven clen on all child and parents.
- doing a maven update dependences on all projects
- doing a maven package on each project.
- doing m2 maven->"update project configurations" on all projects.
- restarting eclipse.
- restarting the computer.
Note 1, in eclipse I have 4 separate projects, one for each child, and one for the parent. the three child projects are also checked into SVN, but I cant easily checkin the parent project as it has the child project folders underneath it.
NOTE 2, I know a lot about ant, but am a noob at maven, but havent had any problems with it till now. e.g. Ive no idea if maven is telling eclipse to use the source of the depentant project, or if it has to compile jar constantly into the local m2 repository, and the dependant project uses that. NOTE 3, all the other (external) dependences are ok. NOTE 4, Ive checked that "Resolve dependencies from Workspace projects" is checked. NOTE 5, in the ecipse java build path dialogue, the peer projects on which it is dependent do not seem to be in either "source", "projects" or "libraries" tabs. Libraries has a "maven depedencies" sub tree, but under thare are just external jars like log4j.Does it work if you do a mvn clean install
on the parent pom from the command line instead of in eclipse? That will rule out two things:
- Whether or not it is an eclipse problem
- Whether or not your problem has to do with you using
package
instead ofinstall
I noticed you were using the maven package goal. In general, you should always do mvm clean install
instead of mvn clean package
for work on your local machine. If you don't use the install goal, then project C never gets installed to your local repository (by default in $HOME/.m2/repository or the equiv in Windows) and thus won't be able to be referenced by projects A and B.
Failing that, go inside of your $HOME/.m2/repository and check the actual installed .jar/.pom for project c. It's directory path will correspond to it's maven coordinates (e.g. com/mydomain/ge/child_project_c/0.0.1-SNAPSHOT). Make sure the jar has the classes you expect inside of it and make sure the pom installed beside it looks like the one in your source repository.
Cannot make a comment yet, but should not m2eclipse resolve workspace projects instead of installing them to local repository and resolving them from there?
I found out, that mvn is pretty picky about what is written within build.properties
! I faced the same problem and had to take care that
- Both
source.. = src/
andoutput.. = bin/
are correctly entered. bin.includes = META-INF,/
and.
are correctly entered.
After I fixed this, mvn clean install did work like a charm! @whaley, thanks for the hint with $HOME/.m2/repository
it actually brought me to see the the files were really missing in the jar, due to the aforementioned reasons!
精彩评论