edwardmlyte
edwardmlyte

Reputation: 16597

How do I manually add a project to the build path of another project?

I have a maven project which won't compile due to an unresolvable reference from another project's artifact.

When I run eclipse:eclipse and open it up it shows an auto fix suggestion of "Add project 'project2' to build path of 'project1'". If I click this everything works. So project1 can clearly see my project2 reference, but doesn't quite use it as expected.

However, once I delete all the files generated for eclipse the error resumes because whatever reference eclipse created has been removed. How can I get this project2 in the project1 build path manually. I already have it listed in the pom as below:

<dependency>
    <groupId>group.id</groupId>
    <artifactId>project2</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>

Upvotes: 3

Views: 3084

Answers (3)

Sinisha Mihajlovski
Sinisha Mihajlovski

Reputation: 1841

If you have maven nature to both your projects, you should do mvn clean install to both the projects, so they will be installed in your local repository and will be available for other projects to use as dependencies. Or just right click to both the projects in eclipse and choose Run As --> Maven install

Upvotes: 0

sleske
sleske

Reputation: 83635

When I run eclipse:eclipse[...]

This sounds like you are using the Maven Eclipse plugin. You should probably rather use m2e, which is the recommended way to integrate with Maven now. This will also obviate the need to run mvn eclipse:eclipse. Instead, just import your Maven project into Eclipse, and it will pick up everything automatically.

After you set "Resolve dependencies from Workspace projects" as described in polypiel's answer, things should just work (TM).

Upvotes: 1

polypiel
polypiel

Reputation: 2341

In "Project properties > Maven" menu you should check "Resolve dependencies from Workspace projects".

Upvotes: 3

Related Questions