使用Maven解压zip内部拉链
我可以通过maven-dependency插件解压zip文件,但是目前我有这个zip文件里面的其他zip文件包含的问题,我也需要解压缩它们。 我怎样才能做到这一点?
你可以使用ant任务运行器插件解压缩任何文件:
<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>
使用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仓库。 例如任务附着工件 org.codehaus.mojo:build-helper-maven-plugin:build-helper:attach-artifact
TrueZIP Maven插件也可以。 示例configuration:
<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>
官方的例子
您也可以使用插件依赖项。 有一个目标来解压依赖关系(请参阅http://maven.apache.org/plugins/maven-dependency-plugin/unpack-dependencies-mojo.html )