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?
Unpack inner zips in zip with Maven
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>
I take it that this is put into your pom.xml file? –
Inoculum
Yes, this is a part of your Maven
pom.xml
file. –
Wilie How can you in this example unzip a file which matches a regular expression? E.g. <unzip src="zips/archive[0-9].zip" dest="output/" /> –
Madea
Try with the wildcard:
<unzip src="zips/archive*.zip" dest="output/" />
–
Wilie Nope this will not work. I had better chance with a fileset instead:
<unzip dest="output"> <fileset dir="zips"> <include name="archive*.zip" /> </fileset> </unzip>
–
Madea 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
But that only unzips artefacts, not arbitrary files. –
Attentive
@OndraŽižka With maven you can treat any "arbitrary" file as artifact, just look at
build-helper:attach-artifact
. –
Telescopium @Telescopium how does one do it with an arbitrary file on the local filesystem? –
Clung
Maybe 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 –
Microminiaturization
When building with Eclipse Juno, the
unpack
goal is not supported by m2e 1.3.1. –
Puli 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. –
Telescopium
I 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. –
Cloistral
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 (tested) or certainly with Ant (but not tested). –
Metallography 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>
Codehaus is shutting down, so the links now go to their "we are reorganizing" page. –
Steersman
@Shaynashayne what is the license of above plugin, I can't find it in their docs –
Fraenum
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)
this response is NOT correct, the question is about a file with an inner zip, NOT a dependency. –
Cloistral
© 2022 - 2024 — McMap. All rights reserved.