Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Maven 2: Copy JAR of Dependent Project to Distribution

 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
I have two Maven projects, A which is the main program and B which is a common library. These projects have a common parent C, which is another Maven project.
I want, during the packaging phase, do the following:
1. Copy the JAR file of project A to a directory "distributable" in the target directory.
2. Copy all the libraries that project A depends on to "distributable/lib".
3. Set the classpath of the JAR file in step 1 to include all libraries copied in step 2.

Problems arise when I try to use the maven-dependency-plugin in step 2, however if I exclude the artifactId of project B, things work fine, except for the JAR file of project B not ending up in the lib directory, of course.
I have read most of "Maven Definitve Guide" and a lot of web pages without finding the solution, so I now ask if anyone here knows how to do this?
Many thanks in advance!
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problems arise when I try to use the maven-dependency-plugin in step2


What kind of problems?
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good question and having answered a fair amount of questions, I should have known better than to omit vital information!
It seems like the plugin is trying to copy from the classes directory of the project B instead of the JAR.

Update:
Here is the error message I get when trying to package project A:
The following mojo encountered an error while executing:
Group-Id: org.apache.maven.plugins
Artifact-Id: maven-dependency-plugin
Version: 2.0
Mojo: copy-dependencies
brought in via: POM

While building project:
Group-Id: com.ivan.mainproject
Artifact-Id: mainproject-art
Version: 1.0.0
From file: /Somepath/mainproject/pom.xml
Reason: Error copying artifact from /Somepath/libproject/target/classes to /Somepath/mainproject/target/dist/lib/classes


Update2:
I seem to have solved it by changing the <packaging> of project B, the library project, to "pom" instead of the original value, which was "jar".
 
tharun Kumar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We ran into a similar issue recently. would you be able to share relevant pom snippets.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch Tharun!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic