1

我正在使用 Maven EAR 插件来生成application.xml我的 EAR,其中包含一个 WAR。

我希望contextRoot在运行时确定 WAR(这要归功于 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.xmlEAR 中生成的内容来做到这一点,它就可以工作。

但是,我无法让 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 替换插件来破解,但这很难看......)

感谢您的任何提示!

4

1 回答 1

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>
于 2014-07-01T09:23:24.787 回答