Possible Duplicate:
With Maven, how can I build a distributable that has my project's jar and all of the dependent jars?
maybe I'm blind, but can the maven assembly plugin just create a zip file containing the current project.jar and all my dependency jars? the "bin" id contains just my project.jar and the jar-with-dependencies puts all together in one jar which I don't like.
We can use -U/--update-snapshots flag when building a maven project to force maven to download dependencies from the remote repository. Here, -U,--update-snapshots : Forces a check for missing releases and updated snapshots on remote repositories.
The difference is that the Maven Assembly Plugin will automatically copy all required dependencies into a jar file. In the descriptorRefs part of the configuration code, we provided the name that will be added to the project name. Output in our example will be named as core-java-jar-with-dependencies. jar.
You need a custom assembly descriptor to do what you want. It's a combination of the bin and the jar-with-dependencies predefined descriptors. Created a custom assembly descriptor called assembly.xml
in the src/main/assembly
folder.
Here's an example that is basically the bin descriptor with the dependency set added:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<formats>
<format>tar.gz</format>
<format>tar.bz2</format>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/site</directory>
<outputDirectory>docs</outputDirectory>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
Then change your pom to use a descriptor instead of a descriptorRef to tell it where your custom descriptor is.
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
[...]
</project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With