views:

347

answers:

3

Hi, I have a spring mvc project in eclipse, and its setup to use maven. I can resolve all my external dependencies, but now I want to include another local project in my workspace. Normally, I would do this through the java build path, and add a project reference. But if I do that manually, m2eclipse just removes those references from my classpath file.

I'm assuming this is because maven wants to handle all dependencies. So I enable dependency management on the local project (the source files i want to include), and now when I add dependencies, this project shows up, and it adds it as a jar type (which is correct). I also ran maven-package to create a snapshot of the source project. But the jar is never added in the maven library list, and the project doesn't build because it can't find the classes.

What am I doing wrong? Thanks for the help!

A: 

You probably need to add the local project (with it's pom.xml artifactId) as a dependency in the pom.xml of the WTP project, and turn on Workspace Dependency resolution?

jayshao
+2  A: 

The configuration of Maven projects in Eclipse is derived by M2Eclipse from the metadata contained in the POMs so if you have two projects, ProjectA and ProjectB, and you want to have ProjectB as dependency of ProjectA, you need to declare ProjectB as such in the POM of ProjectA i.e. to add a dependency:

<dependency>
  <groupId>group.id.of.b</groupId>
  <artifactId>project-b</artifactId>
  <version>1.2.3-SNAPSHOT</version>
</dependency>

And if you want to depend on the project in the workspace (and not on the artifact through the local repository), right-click on ProjectA then go to Properties > Maven and make sure you selected Resolve Dependencies from Workspace projects as illustrated below:

alt text

Pascal Thivent
Hi, thanks for the clear explanation. I've made progress, but there's still a problem. I did as you said, and now I can see when I add the dependency on the local project in the pom, I can see a project folder icon pop into the "Web App Libraries" folder, and some of it's dependencies (jars) are also added. However, I can't click on library and see classes, and my project still won't run because it cant find the classes. Is there something else that needs to be done in order for the classes to be made available?
chrismarx
Also, I re-ran the maven-package command on the local code project, and the resulting jar snapshot does indeed have the classes -- any advice?
chrismarx