Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding referenced Eclipse projects to Maven dependencies

Tags:

Right now, I have two Eclipse projects - they both use Maven 2 for all their jar-dependency goodness.

Inside Eclipse, I have project Foo included in project Bar's build path, so that I can use Foo's classes from project Bar. This works really well in Eclipse land, but when I try:

mvn compile  

inside Bar's directory, it fails because Maven doesn't know about the project-to-project relationship in Eclipse's build path.

If I were using Ant, I would just use it to do something silly like copy foo.jar into project Bar's classpath, but as far as I can tell, things are done a lot less hackishly in Maven-land.

I'm wondering if there's a standard workaround for this type of problem - it seems like it would be fairly common, and I'm just missing something basic about how Maven works.

like image 599
rgcb Avatar asked Sep 25 '08 21:09

rgcb


People also ask

How do I add a project as a dependency of another project in Eclipse?

Instead open the project properties of the second project and select "Java Build Path". On the right side on the "Projects" tab you can add your first project as "required project on the build path". The class files of project 1 are now added to the class path of project 2.

How do I fix missing Maven dependencies in Eclipse?

Right-click on the project and choose Properties, and then Maven. Uncheck the box labeled "Resolve dependencies from Workspace projects" Hit Apply, and then OK. Right-click again on your project and do a Maven->Update Snapshots (or Update Dependencies)


1 Answers

Maybe you are referencing the other project via Eclipse configure-> build path only. This works as long as you use Eclipse to build your project.

Try running first mvn install in project Bar (in order to put Bar in your Maven repository), and then add the dependency to Foo's pom.xml.

That should work!.

like image 158
Pablo Fernandez Avatar answered Sep 19 '22 15:09

Pablo Fernandez