views:

30

answers:

1

Hi,

I've been previously managing a 3-module project as 3 seperate maven projects. As this project has been moving forward, I decided I ought to take advantage of the dependency management of maven2 to streamline integration between these 3 evolving modules.

I defined a super-project that deploys as POM. Some shared dependencies are defined here, and the modules are defined in the POM in the order of dependency from the least dependent module to the most dependent module. Each module has a POM definition back to the parent, and where it applies there are dependencies from one module to the deployed artifact of another module. I'll include possibly worthwhile pom.xml lines at the end.

On to the problem, I setup this project yesterday and was able to get each module building and working on its own. I then come back today to work on one of the modules now that some fresh requirements have come in and all of sudden everything is breaking. I'm editing the projects in Eclipse, and each time I modify a file, it no longer can resolve any of the classes defined within the same project. That is to say if I have a class foo.bar.class1 and it has an object of foo.bar.class2, Eclipse (and the compiler at large) complains that it cannot resolve class foo.bar.class2... Now this is blowing my mind because this other class is in the same project and package. Similar issues are also present for classes not in the same package.

Is there something broken in my maven setup, or does anyone have any idea why these projects can't even resolve classes in the same package??

-::POMs::-

Parent -> /path/to/project/mainApp

<modelVersion>4.0.0</modelVersion>
<groupId>com.moremagic</groupId>
<artifactId>mainApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Main App</name>

<modules>
    <module>Broker</module>
    <module>Soap</module>
    <module>UI</module>
</modules>

Broker -> /path/to/project/mainApp/Broker

 <parent>
   <artifactId>mainApp</artifactId>
   <groupId>com.moremagic</groupId>
   <version>0.0.1-SNAPSHOT</version>
   <relativePath>../</relativePath>
 </parent>

 <modelVersion>4.0.0</modelVersion>

 <groupId>com.moremagic</groupId>
 <artifactId>Broker</artifactId>
 <version>1.0-SNAPSHOT</version>
 <packaging>jar</packaging>

Soap -> /path/to/project/mainApp/Soap

<parent>
  <artifactId>mainApp</artifactId>
  <groupId>com.moremagic</groupId>
  <version>0.0.1-SNAPSHOT</version>
  <relativePath>../</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<groupId>com.moremagic</groupId>
<artifactId>SOAP</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

...

<dependency>
    <groupId>com.moremagic</groupId>
    <artifactId>Broker</artifactId>
    <version>1.0-SNAPSHOT</version>
    <type>jar</type>
    <scope>compile</scope>
</dependency>

...

UI -> /path/to/project/mainApp/UI

<parent>
  <artifactId>mainApp</artifactId>
  <groupId>com.moremagic</groupId>
  <version>0.0.1-SNAPSHOT</version>
  <relativePath>../</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>com.moremagic</groupId>
<artifactId>UI</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

...


<dependency>
  <groupId>com.moremagic</groupId>
  <artifactId>SOAP</artifactId>
  <version>1.0-SNAPSHOT</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>com.moremagic</groupId>
  <artifactId>Broker</artifactId>
  <version>1.0-SNAPSHOT</version>
  <type>jar</type>
  <scope>compile</scope>
</dependency>

...
+1  A: 

It sounds like the problem is with your Eclipse setup and not Maven.

Does mvn compile work from the command-line within your projects? From both the parent project and each individual module (after doing mvn install for the dependencies)?

Are you using a Maven plugin for Eclipse, such as m2eclipse? Check that it is configured to load dependent projects from within Eclipse, rather than looking to the repository ("Enable Workspace Resolution"). What happens if you do Project > Clean to clean out all of the projects?

matt b
That seems to be it. Strange, but thanks for the tip (Project > Clean in Eclipse especially).
Rich
m2eclipse can be great, but sometimes it is really aggravating - I often have to do Project > Clean to get Eclipse to see resources on the classpath, etc.
matt b