如何强制Maven EAR插件在application.xml中使用上下文根变量?
我正在使用Maven EAR插件生成我的EAR的如何强制Maven EAR插件在application.xml中使用上下文根变量?,maven,jboss,maven-ear-plugin,Maven,Jboss,Maven Ear Plugin,我正在使用Maven EAR插件生成我的EAR的application.xml,它包含一个WAR 我希望在运行时确定战争的contextRoot(这要感谢JBoss AS 7),因此application.xml应该包含如下内容: <module> <web> <web-uri>my.war</web-uri> <context-root>${my.context.root}</context-root>
application.xml
,它包含一个WAR
我希望在运行时确定战争的contextRoot
(这要感谢JBoss AS 7),因此application.xml
应该包含如下内容:
<module>
<web>
<web-uri>my.war</web-uri>
<context-root>${my.context.root}</context-root>
</web>
</module>
如果我通过在EAR中编辑生成的application.xml
来实现这一点,它就会起作用
但是,我无法让Maven将${my.context.root}
写入application.xml
中的上下文根
我首先尝试了这一点(因为没有过滤任何内容,所以应该可以使用):
所以我试着逃跑:
<configuration>
<modules>
<webModule>
<groupId>my.group</groupId>
<artifactId>my-war</artifactId>
<contextRoot>\${my.context.root}</contextRoot>
</webModule>
</modules>
</configuration>
我的团队
我的战争
\${my.context.root}
这就是字面意思:
<module>
<web>
<web-uri>my-war.war</web-uri>
<context-root>\${my.context.root}</context-root>
</web>
</module>
我的战争
\${my.context.root}
我怎样才能让Maven做我想做的事?(当然,我可以尝试使用Maven replacer插件来破解application.xml
,但那太难看了……)
谢谢你的提示 好吧,既然没有人知道更好的答案,下面是我如何将
application.xml
破解成的:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<executions>
<execution>
<id>replace-escaped-context-root</id>
<phase>process-resources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<file>${project.build.directory}/${project.build.finalName}/META-INF/application.xml</file>
<regex>false</regex>
<token>\${</token>
<value>${</value>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<modules>
<webModule>
<groupId>my.group</groupId>
<artifactId>my-war</artifactId>
<contextRoot>\${my.context.root}</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
com.google.code.maven-replacer-plugin
替代者
替换转义的上下文根
过程资源
代替
${project.build.directory}/${project.build.finalName}/META-INF/application.xml
假的
\${
${
maven耳朵插件
我的团队
我的战争
\${my.context.root}
这是可行的,但我认为这是错误的。maven-ear插件应该读取contextRoot,但我似乎不是这样。只是一个通知,应该是“\my war”,值应该是“\my new context root”,而不是“\${”。这是上面示例中的特定值,其他用户可能会使用工件名称。例如“/my war”来“/my new context root”(记住/,因为这只会替换上下文根而不是工件名称)。对我有用,但使用了/
而不是\:/${my.context.root}
而不是\${my.context.root}
我想你们都误解了我的用例:我希望application.xml
真正包含${my.context.root}
,不进行任何变量解析/筛选。JBoss AS 7将在部署时解析该变量。
<configuration>
<modules>
<webModule>
<groupId>my.group</groupId>
<artifactId>my-war</artifactId>
<contextRoot>\${my.context.root}</contextRoot>
</webModule>
</modules>
</configuration>
<module>
<web>
<web-uri>my-war.war</web-uri>
<context-root>\${my.context.root}</context-root>
</web>
</module>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<executions>
<execution>
<id>replace-escaped-context-root</id>
<phase>process-resources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<file>${project.build.directory}/${project.build.finalName}/META-INF/application.xml</file>
<regex>false</regex>
<token>\${</token>
<value>${</value>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<modules>
<webModule>
<groupId>my.group</groupId>
<artifactId>my-war</artifactId>
<contextRoot>\${my.context.root}</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>