【问题标题】:Maven: unpack zip artifact to a SPECIFIC folder nameMaven:将 zip 工件解压缩到特定文件夹名称
【发布时间】:2012-02-14 08:38:08
【问题描述】:

我正在尝试下载 tomcat zip 工件并将其解压缩到一个名为 tomcat 的文件夹中。 我得到的是 tomcat/apache-tomcat-7.0.19/ 如何摆脱烦人的中间目录?

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
    <execution>
        <id>unpack-tomcat</id>
        <phase>process-sources</phase>
        <goals>
            <goal>unpack</goal>
        </goals>
        <configuration>
            <artifactItems>
                <artifactItem>
                    <groupId>org.apache</groupId>
                    <artifactId>tomcat</artifactId>
                    <version>7.0.19-win64</version>
                    <type>zip</type>
                    <overWrite>false</overWrite>
                    <outputDirectory>tomcat</outputDirectory>
                    <excludes>webapps/**</excludes>
                </artifactItem>
            </artifactItems>                            
        </configuration>
    </execution>
</executions>
</plugin>

【问题讨论】:

    标签: tomcat maven unpack maven-dependency-plugin


    【解决方案1】:

    使用unpack-depencencies 目标并将useSubDirectoryPerArtifact 设置为false。

    【讨论】:

    • 我无法让它工作。现在它只是给我带来了我得到的所有依赖项,而不是只过滤 tomcat。
    • 在 pom 中插件声明的配置部分下添加 tomcat
    • 我发布了整个 pom 插件代码。它仍然对我不起作用。只需创建嵌套目录
    • 这绝对不起作用,并且根据手册,useSubDirectoryPerArtifact 默认设置为 false。
    • @marcv81 当 OP 可以将其设置为默认值以外的其他值时,默认值没有多大意义。直到我发布我的答案之后,OP 才发布他的 POM。请考虑稍微轻一点。
    【解决方案2】:

    也许有更多“mavenish”的方式来实现我的建议 :) 但是使用 maven ant 插件可能是适合您情况的解决方法:

    <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <configuration>
                                <target>
                                    <move file   = "tomcat/apache-tomcat-7.0.19/*"
                                          tofile = "tomcat" />
                                </target>
                            </configuration>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                        <execution>
                            <phase>package</phase>
                            <configuration>
                                <target>
                                    <delete dir = "tomcat/apache-tomcat-7.0.19"/>
                                </target>
                            </configuration>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                    </executions>
    </plugin>
    

    【讨论】:

      【解决方案3】:

      ma​​ven 使用扁平路径解包

      http://pulkitsinghal.blogspot.com/2011/04/jetspeed-finally-unpack-plugin-with.html:

      绝对没有办法(写这篇博文时我知道) 让这个 maven 插件吐出一个扁平的结构。

      所以一个不错的选择是使用jetspeed-unpack-maven-plugin 允许用户指定&lt;flat&gt;true&lt;/flat&gt; 作为 configuration为了获得想要的文件而无负担 将工件根目录的相对路径包含为 好吧。

      文档指出,此插件还能够将压缩的 maven 工件内的任意相对路径解压缩到特定的目标文件夹。

      【讨论】:

      • 如issues.apache.org/jira/browse/JS2-1366 中报告的那样,该插件可能无法在Maven 3.6 中运行。
      猜你喜欢
      • 2018-10-21
      • 2013-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-10
      • 2015-12-26
      • 2021-05-16
      • 2020-02-04
      相关资源
      最近更新 更多