Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Maven 2: Copy JAR of Dependent Project to Distribution

 
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!
 
Sheriff
Posts: 10445
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".
 
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.
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch Tharun!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic