views:

75

answers:

2

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>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.

+1  A: 

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:

  1. Whether or not it is an eclipse problem
  2. Whether or not your problem has to do with you using package instead of install

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.

whaley
This is good stuff. I tried the maven install target via eclipse (although Im not installing anything?), but this did not help. I then tried the command line "mvs clean install" outside eclipse as directed, then I did a "update project configuration" on the parent, and this seems to have fixed it for now - thanks! Now when I look at the source and library tabs of the eclipse "java build path" dialogue, I see my child project. The question is, why did eclipse suddenly lose these dependences, and when should I be doing manual mvn install commands (i hope not every time I change the source!)
wingnut
Maven's dialect involves some overloading of terms that tend to confuse newcomers. For instance "install" really means "stick the result of the build in my local maven repository". "deploy" really means "deploy this to a remote maven repository". They have nothing to do with the act of installing or deploying software, really.
whaley
A: 

Cannot make a comment yet, but should not m2eclipse resolve workspace projects instead of installing them to local repository and resolving them from there?

Rocky