Maven:将zip artifact解压到特定文件夹名称

11

我试图下载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>
3个回答

7
也许有更多“Maven方式”来实现我的建议 :),但使用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

maven解压缩到平面路径

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

截至本博客发布时,我不知道有任何方法可以让这个maven插件输出一个平面结构。

因此,一个很好的替代方案是使用jetspeed-unpack-maven-plugin,它允许用户在配置中指定<flat>true</flat>以获取所需文件,而不必包含来自根工件的相对路径。

文档说明该插件还能够将Maven工件内任意相对路径解压缩到特定目标文件夹。


插件可能无法在Maven 3.6中正常工作,如issues.apache.org/jira/browse/JS2-1366所报告的那样。 - Kenston Choi

-2

我无法让它工作。现在它只会带给我所有的依赖项,而不仅仅是过滤出tomcat。 - archmisha
在您的pom文件中的插件声明的配置部分中添加<includeArtifactIds>tomcat</includeArtifactIds>。 - BenjaminLinus
我发布了整个POM插件代码。对我来说仍然无法工作。只需创建嵌套目录即可。 - archmisha
这完全不起作用,而且根据手册,默认情况下useSubDirectoryPerArtifact设置为false。 - marcv81
1
@marcv81 默认值并没有太大意义,因为操作者可以将其设置为与默认值不同的值。而且,在我回答之后,操作者才发布了他的POM。请考虑对待问题时更加谨慎。 - BenjaminLinus
@BenjaminLinus:对于我之前的评论过于粗暴,我深感抱歉。我肯定需要冷静一下。 - marcv81

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接