11

I am trying to download tomcat zip artifact and unpack it int a folder named tomcat. What i get is tomcat/apache-tomcat-7.0.19/ How can I get rid of the annoying intermediate directory?

<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>
archmisha
  • 199
  • 1
  • 2
  • 12

3 Answers3

7

Maybe there is more "mavenish" way for achieving my proposal :) yet using maven ant plugin could be a workaround for your situation :

<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>
Shmil The Cat
  • 4,548
  • 2
  • 28
  • 37
3

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.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Vadzim
  • 24,954
  • 11
  • 143
  • 151
-2

Use unpack-depencencies goal and set useSubDirectoryPerArtifact to false.

BenjaminLinus
  • 2,100
  • 23
  • 24
  • I dont manage it to work. Now it just brings me all dependencies I got and doesnt filter only tomcat. – archmisha Jan 19 '12 at 19:44
  • Under the configuration section of your plugin declaration in your pom add tomcat – BenjaminLinus Jan 19 '12 at 20:46
  • I posted the entire pom plugin code. It still doesnt work for me. Just create nested dir – archmisha Jan 25 '12 at 13:43
  • This absolutely does not work, and useSubDirectoryPerArtifact is set to false by default anyway as per the manual. – marcv81 Sep 29 '14 at 17:10
  • 1
    @marcv81 The default value doesn't mean much when the OP could have set it to something other than the default. And the OP didn't post his POM until after I posted my answer. Please think about treading a little more gently. – BenjaminLinus Sep 29 '14 at 19:45
  • @BenjaminLinus: Apologies for the brutality of my previous comment. I definitely need to chill a little. – marcv81 Sep 30 '14 at 12:37