unpack war file after maven clean package

3.3k Views Asked by At

I use maven-assembly-plugin to create a war file under [app-root]/target/my-project-war. How do I unpack this war file so it becomes a folder under application root like [app-root]/war?

The reason I want the war folder instead of target/**.war is that I can use mvn gae:deploy to deploy directly to app engine. The gae:deploy is from maven-gae-plugin and its confirguration only allows me to specify appDir, not a war file.

pom.xml

<plugin>
     <groupId>net.kindleit</groupId>
     <artifactId>maven-gae-plugin</artifactId>
     <version>${gae.plugin.version}</version>
     <configuration>
             <unpackVersion>${gae.version}</unpackVersion>
             <serverId>appengine.google.com</serverId>
             <sdkDir>${gae.home}</sdkDir>
             <appDir>${basedir}/war</appDir>
             <splitJars>true</splitJars>
     </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2.1</version>
    <configuration>
       <appendAssemblyId>false</appendAssemblyId>
       <descriptors>
               <descriptor>${basedir}/assembly-war.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
        <execution>
               <id>make-assembly</id>
               <phase>package</phase>
               <goals>
                   <goal>single</goal>
                   </goals>
        </execution>
    </executions>
 </plugin>

assembly-war.xml

<assembly>
   <id>war</id>

   <formats>
       <format>war</format>
   </formats>

   <includeSiteDirectory>false</includeSiteDirectory>
   <includeBaseDirectory>false</includeBaseDirectory>
   <fileSets>
    ...
   </fileSets>
   <dependencySets>
   </dependencySets>
</assembly>

Here is my project folder. The War folder is in bold.

$ ls -l test-maven-play-plugin/
total 24
drwxr-xr-x   5 angeloh  staff   170 Jan 25 21:45 app
-rw-r--r--@  1 angeloh  staff  2962 Jan 25 23:58 assembly-war.xml
drwxr-xr-x   6 angeloh  staff   204 Jan 25 21:46 conf
drwxr-xr-x  26 angeloh  staff   884 Jan 25 22:42 lib
-rw-r--r--@  1 angeloh  staff  7380 Jan 26 00:05 pom.xml
drwxr-xr-x   4 angeloh  staff   136 Jan 26 00:04 precompiled
drwxr-xr-x   5 angeloh  staff   170 Jan 25 21:45 public
drwxr-xr-x   9 angeloh  staff   306 Jan 26 00:04 target
drwxr-xr-x   6 angeloh  staff   204 Jan 25 22:11 test
drwxr-xr-x   3 angeloh  staff   102 Jan 25 22:15 test-result
drwxr-xr-x   2 angeloh  staff    68 Jan 26 00:04 tmp
drwxr-xr-x   3 angeloh  staff   102 Jan 25 22:10 **war**

----------------------[UPDATE]----------------------

A little progress. If I do these changes:

pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    ......
    <configuration>
       ......
       <outputDirectory>${basedir}/war</outputDirectory> 
    </configuration>
    ......
</plugin>

assembly-war.xml

<assembly>
   <id>war</id>

   <formats>
       <format>dir</format>
   </formats>
   ......
</assembly>

The war content will output to war/test-play-1.0.0. However, I want it directly to war, not war/test-play-1.0.0.

----------------------[UPDATE]----------------------

Finally, after I made these changes, it works for me.

pom.xml

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    ......
    <configuration>
       ......
       <outputDirectory>${basedir}</outputDirectory>
       <finalName>war</finalName> 
    </configuration>
    ......
</plugin>
1

There are 1 best solutions below

1
On

The maven-war-plugin builds the web app into a directory first. By default this directory is ${project.build.directory}/${project.build.finalName} (see the webappDirectory configuration property).

The maven-gae-plugin deploys from an unpacked war. By default, it is the same directory. (see its appDir configuration property)

So you should simply be able to run:

mvn clean package gae:deploy

If you have problems with that, you could consider using war:inplace goal, which will copy class files and resources into src/main/webapp/WEB-INF/classes, and dependencies into src/main/webapp/WEB-INF/lib.