我可以通过 maven-dependency 插件解压缩 zip 文件,但目前我遇到的问题是,在该 zip 文件中包含其他 zip 文件,我也需要将它们解压缩。我怎样才能做到这一点?
问问题
35152 次
4 回答
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>
于 2010-07-16T11:06:13.037 回答
24
使用 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
于 2011-10-04T12:55:41.757 回答
9
TrueZIP Maven 插件也很好用。示例配置:
<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>
于 2015-05-27T13:50:44.750 回答
4
您还可以使用插件依赖项。有一个解包依赖项的目标(参见http://maven.apache.org/plugins/maven-dependency-plugin/unpack-dependencies-mojo.html)
于 2011-03-01T14:57:31.420 回答