我有一个带有一个war
和几个ear
项目的maven项目。每个ear
项目需要稍微不同的war
/WEB-INF/web.xml
。每个ear
的pom.xml
都使用com.google.code.maven-replacer-plugin:replacer
和org.codehaus.mojo:truezip-maven-plugin
来替换web.xml
中的令牌,然后将新的web.xml
放在最终的<project>-app.ear/web.war/WEB-INF
中。这对于构建和创建最终的EAR工件都很有用。
我遇到的问题是,当我使用run
(使用Netbeans,但这不重要)时,用于部署的web.xml
(<project>/target/gfdeploy/first-app/web_war/WEB-INF/web.xml
)是令牌化版本。我尝试为deploy
添加执行阶段,但这不起作用。
如何确保运行部署具有修改过的web.xml
,以便在开发期间测试应用程序?
以下是ear pom.xml
的相关部分
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>package-replace</id>
<phase>package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
<execution>
<id>deploy-replace</id>
<phase>deploy</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>${project.parent.basedir}/${web.xml}</file>
<outputFile>${project.build.directory}/${web.xml}</outputFile>
<replacements>
<replacement>
<token>@REALM_NAME@</token>
<value>${web.realm}</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>truezip-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>package-replace-web-xml</id>
<goals>
<goal>copy</goal>
</goals>
<phase>package</phase>
<configuration>
<files>
<file>
<source>${project.build.directory}/${web.xml}</source>
<outputDirectory>${project.build.directory}/${project.build.finalName}/${web.zip}/WEB-INF</outputDirectory>
</file>
</files>
</configuration>
</execution>
<execution>
<id>package-replace-web</id>
<goals>
<goal>copy</goal>
</goals>
<phase>package</phase>
<configuration>
<files>
<file>
<source>${project.build.directory}/${project.build.finalName}/${web.zip}</source>
<outputDirectory>${project.build.directory}/${project.build.finalName}.ear</outputDirectory>
</file>
</files>
</configuration>
</execution>
<execution>
<id>deploy-replace-web-xml</id>
<goals>
<goal>copy</goal>
</goals>
<phase>deploy</phase>
<configuration>
<files>
<file>
<source>${project.build.directory}/${web.xml}</source>
<outputDirectory>${project.build.directory}/gfdeploy/${project.artifactId}/web-${project.version}_war/WEB-INF</outputDirectory>
</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
发布于 2018-01-31 12:52:58
我建议您保持默认的src/main/webapp/WEB-INF/web.xml在开发期间运行的全部功能。然后,保存一个名为src/main/webapp/WEB-INF/web-ear.xml的类似文件,并进行所有替换准备。
将所有替换插件策略封装在maven配置文件中,并以web-ear.xml文件为目标。在此配置文件中添加一个maven-war插件配置,该配置将在构建过程中使用替代的web-ear.xml文件,而不是默认的web.xml (参阅:http://maven.apache.org/plugins/maven-war-plugin/):
<profiles>
<profile>
<id>change-war-profile</id>
<build>
<plugins>
<!-- all your replacement plugins here -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>src/main/webapp/WEB-INF/web-ear.xml</webXml>
</configuration>
</plugin>
<plugins>
</build>
</profile>
</profiles>
确保在EAR构建过程中激活此配置文件:
mvn package -Pchange-war-profile
发布于 2018-01-22 21:31:06
您可以使用jetty插件运行您的战争,选择运行战争目标。这一目标是一场全面的战争。请参阅:https://www.eclipse.org/jetty/documentation/9.4.x/jetty-maven-plugin.html#running-assembled-webapp-as-war
发布于 2018-01-29 20:24:13
首先,部署阶段(构建生命周期的部署阶段)意味着将产品准备好的工件部署到远程Maven存储库(例如,Nexus或Artifactory)。粗略地说,工件部署可以被看作是复制工件。有关更多细节,请阅读构建生命周期简介。
其次,Apache不支持将应用程序部署到应用服务器。但是,根据您使用的应用程序服务器,有几种方法可以做到这一点。你用哪一种?
JBoss应用服务器- jboss maven-plugin可以找到特殊的插件.请参阅使用实例
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.9.Final</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
...
</project>
类似的插件可以在GlassFish服务器上找到:玻璃鱼-maven-plugin。
此外,如果您可以接受这一点,则可以执行来自Netbeans的2步部署:
mvn package
,在包阶段配置所有插件。希望这能有所帮助。
https://stackoverflow.com/questions/48390170
复制相似问题