Today I was trying to make a simple tarball of a project + its dependent jar using the maven-assembly-plugin. I know this is a terrible way to do anything, but hey, just in case someone else wants to do something just as terrible, here are my pom.xml and assembly.xml (the assembly descriptor):
$ tree . ├── assembly.xml ├── pom.xml └── src └── main └── java └── AssemblyExample.java
$ cat pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>myproject</artifactId> <name>My Projects</name> <version>0.1</version> <build><plugins><plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2.1</version> <configuration><descriptors> <descriptor>assembly.xml</descriptor> </descriptors></configuration> <executions> <execution> <phase>package</phase> <goals><goal>attached</goal></goals> </execution></executions> </plugin></plugins></build> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.2</version> </dependency> </dependencies> </project>
$ cat assembly.xml <?xml version="1.0" encoding="UTF-8"?> <assembly> <id>ap3</id> <formats> <format>tar.gz</format> </formats> <includeBaseDirectory>true</includeBaseDirectory> <dependencySets> <dependencySet> <outputDirectory>jars</outputDirectory> <scope>runtime</scope> </dependencySet> </dependencySets> </assembly>
$ mvn package ... [INFO] Compiling 1 source file to /home/andrebal/Desktop/assemblyexample/target/classes [INFO] ... [INFO] Building jar: /home/andrebal/Desktop/assemblyexample/target/myproject-0.1.jar ... [INFO] --- maven-assembly-plugin:2.2.1:attached (default) @ myproject --- [INFO] Reading assembly descriptor: assembly.xml [INFO] Building tar : /home/andrebal/Desktop/assemblyexample/target/myproject-0.1-ap3.tar.gz ... [INFO] BUILD SUCCESS
$ tar -tzf target/myproject-0.1-ap3.tar.gz myproject-0.1/jars/slf4j-log4j12-1.7.2.jar myproject-0.1/jars/slf4j-api-1.7.2.jar myproject-0.1/jars/log4j-1.2.17.jar myproject-0.1/jars/myproject-0.1.jar