我用过滤器创建了一个简单的ear项目。我想对每个环境使用不同的设置,这些设置应该以env-条目的形式传递给生成的application.xml文件。ear包的生成是用maven-ear插件完成的,如下所示:
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.9</version>
<configuration>
<generateApplicationXml>true</generateApplicationXml>
<version>6</version>
<envEntries>
<env-entry>
<env-entry-name>customProperty</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>${custom.property}</env-entry-value>
</env-entry>
</envEntries>
<applicationName>${custom.property}</applicationName>
</configuration>
</plugin>为了做到这一点,我不得不使用另一个插件属性-maven-插件。它成功地从文件中读取属性并将其设置为maven项目属性,因此我可以使用${}.将它们插入到pom.xml文件中。它适用于大多数<applicationName>,元素(例如,不幸的是,当我将它放置到env-entry元素中时,没有成功地查找它,而我需要它。下面是生成的application.xml.
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
<application-name>default property</application-name>
<display-name>test</display-name>
<env-entry>
<env-entry-name>customProperty</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>${custom.property}</env-entry-value>
</env-entry>
</application>这可能是一个应该在Maven耳塞发布的错误,但我在那里没有帐户。我还附加了存档的maven项目,如果有人想亲自检查这个项目:test.zip。
编辑
我已经设法克服了这个问题,使用maven-resource-plugin和过滤application.xml文件后,它是创建的用户@趋向99提议。由于无法替换该文件,所以必须将其复制到META目录。我不漂亮,我知道,但它解决了目前的情况。下面是maven-resource-plugin的附加标记
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<outputDirectory>${basedir}/target/${project.artifactId}-${project.version}/META-INF</outputDirectory>
<filters>
<filter>src/main/filters/${env}.properties</filter>
</filters>
<encoding>UTF-8</encoding>
</configuration>
</plugin>也在这里:
<resources>
<resource>
<directory>${basedir}/target</directory>
<filtering>true</filtering>
<includes>
<include>application.xml</include>
</includes>
</resource>
</resources>可以从这里下载整个项目配置。
发布于 2014-05-19 12:47:52
使用当前的设置,这很可能是不可能的。
我只是简单地看了一下代码,它说env条目是通过PlexusConfiguration加载的。
如果不深入到代码中,我看不出这个部分处理的条目比"read,放入列表“更特殊。
https://stackoverflow.com/questions/23734249
复制相似问题