In some maven projects is important generate a compressed file, for example to send by email.
So, in this post I will show you how you can generate compressed files using Maven.
In you pom.xml file you need incorporate the maven-assembly-plugin plugin, something like that:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-assembly-plugin</artifactId> | |
<configuration> | |
<descriptor>src/assembly/bin.xml</descriptor> | |
<finalName>${plugin.name}</finalName> | |
</configuration> | |
<executions> | |
<execution> | |
<phase>package</phase> | |
<goals> | |
<goal>single</goal> | |
</goals> | |
</execution> | |
</executions> | |
</plugin> |
So, as you can see, you need define a bin.xml file in src/assembly/ path, you can define the name and path that you want. Is only mandatory have a specific structure content. That you can see a example below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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"> | |
<formats> | |
<format>zip</format> | |
<format>tar</format> | |
<format>tar.gz</format> | |
<format>tar.bz2</format> | |
</formats> | |
<includeBaseDirectory>false</includeBaseDirectory> | |
<dependencySets> | |
<dependencySet> | |
<includes> | |
<include>groupId.example:artifactId.example</include> | |
</includes> | |
<unpack>false</unpack> | |
<scope>runtime</scope> | |
<outputDirectory>${plugin.name}</outputDirectory> | |
</dependencySet> | |
</dependencySets> | |
<fileSets> | |
<fileSet> | |
<directory>resources</directory> | |
<outputDirectory>${plugin.name}</outputDirectory> | |
<includes> | |
<include>file-example.xml</include> | |
<include>file-example.png</include> | |
</includes> | |
</fileSet> | |
<fileSet> | |
<directory>target</directory> | |
<outputDirectory>${plugin.name}</outputDirectory> | |
<includes> | |
<include>build-*.jar</include> | |
</includes> | |
</fileSet> | |
</fileSets> | |
</assembly> |
That example, permit create zip, tar, tar.gz, tar.bz2. If you want put all dependencies on the compress file, you don't need define includes tag.
More details about maven-assembly-plugin: http://maven.apache.org/plugins/maven-assembly-plugin
I hope that information is useful for you. Feel free to comment this post.