在maven clean包之后解压war文件

时间:2012-01-26 07:46:50

标签: maven maven-plugin maven-3 maven-assembly-plugin maven-gae-plugin

我使用maven-assembly-plugin在[app-root] / target / my-project-war下创建一个war文件。如何解压该war文件,使其成为应用程序根目录下的文件夹,如[app-root] / war?

我想要war文件夹而不是target / ** .war的原因是我可以使用mvn gae:deploy直接部署到app引擎。 gae:deploy来自maven-gae-plugin,其确认只允许我指定appDir,而不是war文件。

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

组装war.xml

<assembly>
   <id>war</id>

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

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

这是我的项目文件夹。 War文件夹以粗体显示。

$ 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] ----------------------

稍微进步一点。如果我做了这些改变:

的pom.xml

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

组装war.xml

<assembly>
   <id>war</id>

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

战争内容将输出到war / test-play-1.0.0。 但是,我希望它直接用于战争,而不是war / test-play-1.0.0。

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

最后,在我做出这些修改后,它对我有用。

的pom.xml

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

1 个答案:

答案 0 :(得分:0)

maven-war-plugin首先将Web应用程序构建到目录中。默认情况下,此目录为${project.build.directory}/${project.build.finalName}(请参阅webappDirectory配置属性)。

maven-gae-plugin从一场未解决的战争中部署。默认情况下,它是相同的目录。 (参见其appDir配置属性)

所以你应该只能运行:

mvn clean package gae:deploy

如果您遇到问题,可以考虑使用war:inplace目标,它将类文件和资源复制到src / main / webapp / WEB-INF / classes,并将依赖项复制到src / main / webapp / WEB- INF / lib中。