*
The moose likes Ant, Maven and Other Build Tools and the fly likes Maven 2: Copy JAR of Dependent Project to Distribution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Maven 2: Copy JAR of Dependent Project to Distribution" Watch "Maven 2: Copy JAR of Dependent Project to Distribution" New topic
Author

Maven 2: Copy JAR of Dependent Project to Distribution

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
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

Joined: Jul 20, 2005
Posts: 9963
    
163

Problems arise when I try to use the maven-dependency-plugin in step2


What kind of problems?


[My Blog] [JavaRanch Journal]
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
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

Joined: Nov 18, 2009
Posts: 1
We ran into a similar issue recently. would you be able to share relevant pom snippets.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Welcome to Javaranch Tharun!


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maven 2: Copy JAR of Dependent Project to Distribution
 
Similar Threads
How do I add a jar file to artifactory?
Maven archetypes broken?
Can some one please explain why do i need MAVEN here
Glassfish: Problem connecting two projects, one a WAR and another just a JAR
Maven: What's the big deal?