2010-07-16 25 views
34

我可以通过Maven的依赖插件解压压缩文件,但目前这个问题我已经是那个压缩文件内的其他的zip文件包括,我需要解压它们。我怎样才能做到这一点?解压内拉链与Maven

回答

42

可以解压使用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> 
+0

我认为,这是把你的pom.xml文件? – 2013-03-18 15:21:37

+0

是的,这是你的Maven'pom.xml'文件的一部分。 – 2013-03-19 09:23:24

+0

在这个例子中,你如何解压缩与正则表达式匹配的文件?例如。 <解压SRC = “拉链/存档[0-9]的.zip” DEST = “输出/”/> – 2016-02-24 15:00:07

21

使用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

+16

但是,只解压缩文物,而不是任意文件。 – 2012-07-20 11:37:29

+0

@OndraŽižka通过maven,你可以将任意“任意”文件视为工件,只需看看'build-helper:attach-artifact'。 – MariuszS 2014-01-11 00:14:39

+2

@MariuszS如何用本地文件系统上的任意文件进行操作? – tojofo 2014-03-20 05:53:28

7

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> 

Official examples

+1

Codehaus正在关闭,现在链接转到他们的“我们正在重组”页面。 – 2015-10-20 20:27:59

+0

@palacsint上述插件的许可证是什么,我无法在他们的文档中找到它 – 2017-11-07 11:19:14