I can unpack zip file via the maven-dependency plugin, but currently I have the problem that inside that zip file other zip files are include and I need to unpack them as well. How can I do this?
Asked
Active
Viewed 3.7k times
4 Answers
43
You can unzip any files using ant task runner plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>prepare</id>
<phase>validate</phase>
<configuration>
<tasks>
<echo message="prepare phase" />
<unzip src="zips/archive.zip" dest="output/" />
<unzip src="output/inner.zip" dest="output/" />
<unzip dest="output">
<fileset dir="archives">
<include name="prefix*.zip" />
</fileset>
</unzip>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

Boris Pavlović
- 63,078
- 28
- 122
- 148
-
I take it that this is put into your pom.xml file? – Rob Avery IV Mar 18 '13 at 15:21
-
Yes, this is a part of your Maven `pom.xml` file. – Boris Pavlović Mar 19 '13 at 09:23
-
How can you in this example unzip a file which matches a regular expression? E.g.
– Georgios Stathis Feb 24 '16 at 15:00 -
Try with the wildcard: `
` – Boris Pavlović Feb 24 '16 at 15:01 -
1Nope this will not work. I had better chance with a fileset instead: `
24
Using ANT is not cool any more ;)
http://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-artifacts.html
Sample code for unpacking zip (archive.zip) file:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>foo</groupId>
<artifactId>archive</artifactId>
<version>1.0-SNAPSHOT</version>
<type>zip</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
File archive.zip should be installed into maven repository first. For example with task Attach artifact
org.codehaus.mojo:build-helper-maven-plugin:build-helper:attach-artifact

Arie Laxed
- 103
- 1
- 4

MariuszS
- 30,646
- 12
- 114
- 155
-
18
-
@OndraŽižka With maven you can treat any "arbitrary" file as artifact, just look at `build-helper:attach-artifact`. – MariuszS Jan 11 '14 at 00:14
-
2@MariuszS how does one do it with an arbitrary file on the local filesystem? – tojofo Mar 20 '14 at 05:53
-
4Maybe ant is not cool, but requires much fewer lines and produces the same result. Also, if you attach an artifact with build-helper, it generates many other unpleasant side effects – Alexander Pogrebnyak Jul 07 '14 at 17:34
-
When building with Eclipse Juno, the `unpack` goal is not supported by m2e 1.3.1. – Stephan Dec 29 '15 at 15:01
-
In general binary (zip) files should be stored outside VCS (GIT) repository, for example can be deployed to artifact repository (nexus). After this, you can unpack such artifact as described above. – MariuszS Apr 21 '16 at 14:04
-
1I did the test and this WON'T unzip inner zip files. It's better to use the Ant plugin as described in the other answer. – Sergio Jun 07 '16 at 14:04
-
With `maven-dependency-plugin:unpack` on a zip generated in another module of the same project, I need 2 builds for changes to go through (probably `unpack` takes the zip from the local repository which is updated in a later phase). This problem obviously doesn't occur with [TrueZip's answer](https://stackoverflow.com/a/30484505/7251133) (tested) or certainly with Ant (but not tested). – Florian H. Apr 06 '22 at 09:30
10
TrueZIP Maven Plugin also works well. Sample config:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>truezip-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>copy-package</id>
<goals>
<goal>copy</goal>
</goals>
<phase>package</phase>
<configuration>
<verbose>true</verbose>
<fileset>
<directory>outer.zip</directory>
<outputDirectory>${project.build.directory}/outer</outputDirectory>
</fileset>
<fileset>
<directory>${project.build.directory}/outer/inner.zip</directory>
<outputDirectory>${project.build.directory}/inner</outputDirectory>
</fileset>
</configuration>
</execution>
</executions>
</plugin>
-
1Codehaus is shutting down, so the links now go to their "we are reorganizing" page. – Troy Daniels Oct 20 '15 at 20:27
-
@palacsint what is the license of above plugin, I can't find it in their docs – Kasun Siyambalapitiya Nov 07 '17 at 11:19
1
You can also use the plugin dependencies. There is a goal to unpack dependencies (see http://maven.apache.org/plugins/maven-dependency-plugin/unpack-dependencies-mojo.html)

benzen
- 6,204
- 4
- 25
- 37
-
3this response is NOT correct, the question is about a file with an inner zip, NOT a dependency. – Sergio Jun 07 '16 at 13:48