How to create zip in Maven

The other day I was looking for a maven plugin to create a zip file of the target folder but it turns out that there is the maven-assembly-plugin that can do this already among other things.

First we need to add the plugin in POM:

<plugins>
  		<plugin>
  			<groupId>org.apache.maven.plugins</groupId>
  			<artifactId>maven-assembly-plugin</artifactId>
  			<version>2.2.1</version>
  			<configuration>
  				<descriptors>
  					<descriptor>src/main/assembly/zip.xml</descriptor>
  				</descriptors>
  			</configuration>
  		</plugin>
  	</plugins>

along with the following descriptor under src/main/assembly/zip.xml

<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>myZip</id>
  <baseDirectory>/</baseDirectory>
  <formats>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${project.build.directory}</directory>
    </fileSet>
  </fileSets>
</assembly>

Then it all comes down to:

mvn clean package assembly:assembly
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s