我可以通过maven-dependency插件解压缩zip文件,但是目前我的问题是在zip文件中包含其他zip文件,我也需要解压它们。我怎么能这样做?
答案 0 :(得分:43)
您可以使用ant task runner插件解压缩任何文件:
<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>
答案 1 :(得分:23)
使用ANT不再酷了;)
http://maven.apache.org/plugins/maven-dependency-plugin/examples/unpacking-artifacts.html
解压缩zip(archive.zip)文件的示例代码:
<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>
文件archive.zip应首先安装到maven存储库中。例如,使用任务Attach artifact
org.codehaus.mojo:build-helper-maven-plugin:build-helper:attach-artifact
答案 2 :(得分:9)
TrueZIP Maven Plugin也很有效。示例配置:
<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>
答案 3 :(得分:3)
您还可以使用插件依赖项。 有一个解包依赖关系的目标(参见http://maven.apache.org/plugins/maven-dependency-plugin/unpack-dependencies-mojo.html)