We're trying to build a client jar that includes unpacked dependent jar's. And the manifest should have class-path
entries to the dependent jars. The snippet below works but the jars are unpacked - how can we stop the jars from being unpacked?
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
You can add your dependencies as jar files to your jar:
assembly-descriptor.xml
pom.xml
But unfortunately you can't use the
Class-Path
header inmanifest.mf
, see Adding Classes to the JAR File's Classpath:Indeed, assembling using
jar-with-dependencies
causes maven to unpack all the dependencies as${assembly.dependencySets.dependency.unpack}
is set totrue
in the corresponding assembly descriptor.A simple fix would be to provide an assembly descriptor similar to the
jar-with-dependencies.xml
and modify${assembly.dependencySets.dependency.unpack}
tofalse
, like this:EDIT: For an unknown reason, the behavior when using
<unpack>false</unpack>
is not exactly the same and it seems necessary to add<outputDirectory>/</outputDirectory>
to the fileSet or you don't get the expected result.The solution proposed by Pascal Thivent defines a new assembly for the Maven assembly plugin. The Maven assembly plugin offers defaults assemblies which are 'bin', 'jar-with-dependencies', 'project' and 'src' producing various predefined bundles.
A new assembly has to be defined in a new xml file, most of the time located in src/assemble. Then it will be loaded instead of the predefined one, this way: