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>
4

3 回答 3

6

也许有更多“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>
于 2013-03-11T23:53:53.103 回答
2

maven unpack with flat path

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

There is absolutely no way (known to me as of this blog post writing) to get this maven plugin to spit out a flat structure.

So a good alternative is to use the jetspeed-unpack-maven-plugin which allows the users to specify <flat>true</flat> as part of the configuration in order to obtain the desired file without the burden of having the relative path from the root of the artifact included as well.

Docs state that this plugin is also able to unzip arbitrary relative path inside zipped maven artifact to specific destination folder.

于 2013-09-06T14:17:35.697 回答
-2

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

于 2012-01-19T18:05:02.090 回答