问题
I'm using the Maven EAR plugin to generate the application.xml
of my EAR, which contains a WAR.
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>
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>
If I do this by editing the generated application.xml
in the EAR, it works.
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>
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>
So I tried escaping:
<configuration>
<modules>
<webModule>
<groupId>my.group</groupId>
<artifactId>my-war</artifactId>
<contextRoot>\${my.context.root}</contextRoot>
</webModule>
</modules>
</configuration>
This is then taken literally:
<module>
<web>
<web-uri>my-war.war</web-uri>
<context-root>\${my.context.root}</context-root>
</web>
</module>
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...)
Thanks for any hints!
回答1:
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>
来源:https://stackoverflow.com/questions/24456379/how-can-i-force-the-maven-ear-plugin-to-use-a-context-root-variable-within-appli