-->

我如何可以强制Maven的EAR插件的application.xml中使用上下文根变量?(How c

2019-10-20 08:37发布

我使用Maven的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>
  </web>
</module>

这是通过将系统属性my.context.root内的JBoss AS 7和配置JBoss,以取代XML描述符文件中的变量:

<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>

如果我这样做,通过编辑生成application.xml的EAR,它的工作原理。

但是,我不能让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>

显然,即使filtering默认为false时,Maven仍然认为它应该以此作为Maven的财产。 其结果是,EAR插件只是把在WAR的名字:

<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的做我想做什么? (当然,我可以尝试破解application.xml使用Maven的替代品的插件,但是这是丑陋的...)

感谢您的任何提示!

Answer 1:

那么,既然没有人知道一个更好的答案,这里就是我砍死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>


文章来源: How can I force the Maven EAR plugin to use a context root variable within application.xml?