如何强制Maven EAR插件在application.xml中使用上下文根变量? [英] How can I force the Maven EAR plugin to use a context root variable within application.xml?
问题描述
我正在使用Maven EAR插件生成包含WAR的EAR的application.xml
.
I'm using the Maven EAR plugin to generate the application.xml
of my EAR, which contains a WAR.
我希望在运行时确定WAR的contextRoot
(这要归功于JBoss AS 7),因此application.xml
应该包含以下内容:
I want the contextRoot
of that WAR to be determined at runtime (this works thanks to JBoss AS 7), so the application.xml
should contain something like this:
<module>
<web>
<web-uri>my.war</web-uri>
<context-root>${my.context.root}</context-root>
</web>
</module>
这可以通过在JBoss AS 7中设置系统属性my.context.root
并配置JBoss来替换XML描述符文件中的变量来实现:
This works by setting the System Property my.context.root
within JBoss AS 7 and configuring JBoss to replace variables within XML descriptor files:
<system-properties>
<property name="my.context.root" value="/foo"/>
</system-properties>
<subsystem xmlns="urn:jboss:domain:ee:1.1">
<spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
<jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
</subsystem>
如果我通过在EAR中编辑生成的application.xml
来执行此操作,那么它将起作用.
If I do this by editing the generated application.xml
in the EAR, it works.
但是,我无法让Maven将${my.context.root}
写入application.xml
中的上下文根.
However, I can't get Maven to write ${my.context.root}
into the context root within application.xml
.
我首先尝试了此操作(因为没有过滤任何内容,所以应该可以使用):
I tried this first (since nothing is filtered, it should work):
<configuration>
<modules>
<webModule>
<groupId>my.group</groupId>
<artifactId>my-war</artifactId>
<contextRoot>${my.context.root}</contextRoot>
</webModule>
</modules>
</configuration>
显然,即使filtering
默认为false
,Maven仍然认为应将其用作Maven属性.结果是EAR插件仅输入WAR的名称:
Apparently, even though filtering
defaults to false
, Maven still thinks it should use this as Maven property. The result is that the EAR plugin just puts in the WAR's name:
<module>
<web>
<web-uri>my-war.war</web-uri>
<context-root>/my-war</context-root>
</web>
</module>
所以我尝试了转义:
<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>
我怎样才能让Maven做我想做的事情? (当然,我可以尝试使用Maven替换器插件来破解application.xml
,但这很丑...)
How can I get Maven to do what I want? (Of course, I could try to hack application.xml
by using the Maven replacer plugin, but that's ugly...)
感谢任何提示!
推荐答案
好吧,因为没人知道更好的答案,所以这是我将application.xml
砍成形状的方法:
Well, since nobody knows a better answer, here's how I hacked application.xml
into shape:
<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>
这篇关于如何强制Maven EAR插件在application.xml中使用上下文根变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!