在maven清理包后打开war文件



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

我想要war文件夹而不是target/**.war的原因是我可以使用mvn-gae:deploy直接部署到应用程序引擎。gae:deploy来自maven gae插件,它的配置只允许我指定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>

assembly-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**

----------------------[更新]------------------------

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

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>

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

----------------------[更新]------------------------

最后,在我做了这些改变之后,它对我有效

pom.xml

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

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

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

所以你应该能够简单地运行:

mvn clean package gae:deploy

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

最新更新