maven clean包后解压war文件
我使用 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>
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 内容将输出到 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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
maven-war-plugin 首先将 Web 应用程序构建到一个目录中。默认情况下,此目录为
${project.build.directory}/${project.build.finalName}
(请参阅 webappDirectory 配置属性)。maven-gae-plugin 从未打包的战争中部署。默认情况下,它是同一目录。 参阅其 appDir 配置属性)
(请 应该能够简单地运行:
如果你有问题,你可以考虑使用 war:inplace 目标,它将类文件和资源复制到 src/main/webapp/WEB-INF/classes 中,并且依赖项放入 src/main/webapp/WEB-INF/lib 中。
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:
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.