1

I have a project in eclipse (let's call it project A) which is a Maven project. It is a library which is used by other projects.

And I have project B which is also a Maven project and it depends on project A. In project B's pom.xml I have added a dependency referencing project A, and it builds and runs perfectly from Eclipse.

Now I want to build an executable JAR from project B. Previously I have done this by adding the maven-assembly-plugin plugin to the pom.xml and then running mvn assembly:single from the command line.

When I run mvn assembly:single command within project B it throws an error saying it cannot find project A.

Now what would be the best way to build the executable JAR for B? Is there a way to build it from Eclipse (and presumably it will handle the dependency references as it has been doing) or is there a way to tell Maven that project A is local and it should build project B using the local project A.

Alex Angelini
  • 459
  • 1
  • 4
  • 12
  • 2
    Have you installed project A using Maven's `install` command? – rolve Jun 25 '12 at 17:41
  • I had never heard of that command, I am searching for an example usage now – Alex Angelini Jun 25 '12 at 17:51
  • http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven see this link i think it may help.. – Sourav Jun 25 '12 at 18:04
  • http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven use this link as reference it may help.... – Sourav Jun 25 '12 at 18:06

1 Answers1

2

When using a Maven project as a dependency outside of Eclipse, you have to install it into the local repository first. You do this using the install command:

install: install the package into the local repository, for use as a dependency in other projects locally

This quote is from the Maven in 5 Minutes tutorial.


The "problem" is that Eclipse will build Maven projects with its internal compiler like any other project. As Maven dependencies are mapped to normal Eclipse dependencies for that, you don't have to install your projects. However, as soon as you actually use Maven to build them (even in Eclipse), you do.

rolve
  • 10,083
  • 4
  • 55
  • 75
  • All the install examples seem to have you point towards a JAR file, does that I mean I need to manually build project A first and point then install A within B. Could maven not know to build A then build B? – Alex Angelini Jun 25 '12 at 18:03
  • 1
    No. All the information Maven has is that you have a dependency to some project with a certain group, name and version. If it does not find it in the local repository (on your machine), in the standard repository (Maven Central) or in some additional repository configured in the POM file, it won't know what to do. – rolve Jun 25 '12 at 18:06
  • 1
    So yes, you simply first `install` project A and then you can build project B. – rolve Jun 25 '12 at 18:07
  • There must surely be a way to build and install the local project dependencies, and then build the main project, in a single command or action in Eclipse. Right? – Andy Jan 04 '16 at 17:16
  • Not as far as I know, at least not in general. However, you can set up your projects as modules of an aggregator project and build them all together: https://maven.apache.org/guides/mini/guide-multiple-modules.html – rolve Jan 07 '16 at 07:56