1

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

我想要 war 文件夹而不是 target/**.war 的原因是我可以使用 mvn gae:deploy 直接部署到应用程序引擎。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>

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

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

程序集-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>
4

1 回答 1

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 .

于 2012-01-26T12:18:54.800 回答