【发布时间】:2018-01-22 20:59:15
【问题描述】:
我有一个 maven 项目,其中有一个 war 和几个 ear 项目。每个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,以便在开发期间测试我的应用?
这里是耳朵的相关部分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>
【问题讨论】:
-
那些 EAR/web.xml 文件有什么区别?顺便提一句。为什么不把合适的web.xml放到对应的war模块中呢?
-
WAR 对所有 EAR 项目都是通用的,不同之处仅在于身份验证领域。每个 EAR 都有几个 EJB 模块以及公共 WAR。一些 EJB 是通用的,并包含在所有 EAR 中,其他的则是包含它的 EAR 的自定义。
/WEB-INF/web.xml 现在唯一的区别是身份验证领域,因为每个领域都需要有自己的身份验证领域名称。 -
您是否考虑过像tomcat.apache.org/tomcat-7.0-doc/mbeans-descriptors-howto.html这样的另一种方法?
-
使用 Payara。这不是运行时问题,而是开发问题。生产版本很好。
标签: java maven netbeans netbeans-8