Adding referenced Eclipse projects to Maven dependencies

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


Check out the m2eclipse plugin. It will automatically and dynamically update the project build path when you change the pom. There is no need for running mvn eclipse:eclipse.

The plugin will also detect if any dependency is in the same workspace and add that project to the build path.

Ideally, if you use m2eclipse, you would never change the project build path manually. You would always edit pom.xml instead, which is the proper way to do it.

As has been previously stated, Maven will not know about the Eclipse project build path. You do need to add all dependencies to the pom, and you need to make sure all dependencies are built and installed first by running mvn install.

If you want to build both projects with a single command then you might find project aggregation interesting.


You might want to try an alternative approach, where you have a parent maven project and two children project. let's say:

Parent (pom.xml has references to both children projects/modules) --> A (depends on B) --> B

then when you run mvn eclipse:eclipse from the root of Parent, maven will generate eclipse projects for A and B, and it will have B as a required project in the classpath of A.

You can run mvn install from the root of Parent to get both projects to compile.

To complete your setup, you'll have to import both A and B into Eclipse, making sure you don't check "Copy projects into workspace".


I just needed to do this and I needed it to build with the external mvn clean install command. Here is the proper way to configure this in Eclipse. (With project B as a dependency of A)

  1. Open the pom.xml for project A in Eclipse.
  2. Go to the Dependencies tab.
  3. Click the Add... button in the middle of the page (for the left side Dependencies box)
  4. In the popup, there should be a box under a line with text above it saying Enter groupId, artifactId or sha1 prefix or pattern (*):. Enter the artifact ID for project B into this box.
  5. Double click the jar you want to add as a dependency to this project
    1. You may need to update the project after.
    2. Right click project A in you Package explorer
    3. Maven -> Update Project...
    4. Then hit OK in the popup.