2

I am creating a jar-with-dependencies in mvn 3.0.3. I have successfully done this in one project (using just mvn install) and created a complete jar-wth-dependencies. I copied the relevant chunk of POM code (<plugins>...</plugins>, which someone else wrote!) to the current project (which differs in that it has assemblies). It creates the normal snapshot jar (jumbo-converters-compchem-gaussian-0.3-SNAPSHOT.jar) but no jar-with-dependencies. How should I amend the POM?

<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>cml</groupId> <artifactId>jumbo-converters</artifactId> <version>0.3-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> <artifactId>jumbo-converters-compchem-gaussian</artifactId> <name>jumbo-converters-compchem-gaussian</name> <dependencies> <dependency> <groupId>${jumbo.groupId}</groupId> <artifactId>jumbo</artifactId> </dependency> <dependency> <groupId>cml</groupId> <artifactId>jumbo-converters-core</artifactId> </dependency> <dependency> <groupId>cml</groupId> <artifactId>jumbo-converters-compchem-common</artifactId> <version>0.3-SNAPSHOT</version> </dependency> <dependency> <groupId>cml</groupId> <artifactId>jumbo-converters-templates</artifactId> <version>0.3-SNAPSHOT</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>cml</groupId> <artifactId>jumbo-converters-testutils</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>cml</groupId> <artifactId>jumbo-converters-compchem-testutils</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>org.xmlcml.cml.converters.compchem.gaussian.GaussianLogXML2CompchemConverter</mainClass> </manifest> </archive> <excludes> <exclude>.hgsub</exclude> <exclude>**/.hg/</exclude> <exclude>**/.project</exclude> <exclude>**/external/</exclude> </excludes> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>org.xmlcml.cml.converters.compchem.gaussian.GaussianLogXML2CompchemConverter</mainClass> </manifest> </archive> <excludes> <exclude>.hgsub</exclude> <exclude>**/.hg/</exclude> <exclude>**/.project</exclude> <exclude>**/external/</exclude> </excludes> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> 

2
  • 2
    Have you tried mvn assembly:single ? Commented Jun 4, 2013 at 12:54
  • No. I will try it (have never used it before) Commented Jun 4, 2013 at 12:55

1 Answer 1

2

First, Use maven dependency plugin to retrieve/store the dependencies (more info here) to your project folder. Ex: Say lib folder.

Now mark this lib folder as a "Resources" folder. Like,

<resources> <resource> <directory>lib</directory> <targetPath>lib</targetPath> </resource> </resources> 

Now mvn install should include the dependencies in your final artifact. (copying Shinchan's comment to here so it can be formatted:

Simple add this to ur pom.

<build> <resources> <resource> <directory>lib</directory> <targetPath>lib</targetPath> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.8</version> <executions> <execution> <phase>install</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>lib</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build> 
Sign up to request clarification or add additional context in comments.

1 Comment

Simple add this to ur pom.<build> <resources> <resource> <directory>lib</directory> <targetPath>lib</targetPath> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.8</version> <executions> <execution> <phase>install</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>lib</outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.