【发布时间】:2017-10-31 13:40:55
【问题描述】:
我想根据属性文件的值更新我的 context.xml 和 web.xml 文件的内容。我想设置可供我的网络应用程序使用的数据库连接。是否可以以动态方式添加此内容?
我目前正在使用我的 POM 中的以下构建部分进行一些更新
<build>
<finalName>ROOT</finalName>
<filters>
<filter>src/main/resources/environmentProperties/env1.properties</filter>
<filter>src/main/resources/environmentProperties/env2.properties</filter>
<filter>src/main/resources/environmentProperties/env3.properties</filter>
<filter>src/main/resources/environmentProperties/env4.properties</filter>
</filters>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin-version}</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}\src\main\resources\META-INF</directory>
<filtering>true</filtering>
<targetPath>META-INF</targetPath>
<includes>
<include>**\context.xml</include>
</includes>
</resource>
</webResources>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
</build>
在我的 web.xml 文件中,我有以下内容
<resource-ref>
<description>Env1 Database Connection</description>
<res-ref-name>jdbc/Env1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>Env2 Database Connection</description>
<res-ref-name>jdbc/Env2</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>Env3 Database Connection</description>
<res-ref-name>jdbc/Env3</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>Env4 Database Connection</description>
<res-ref-name>jdbc/Env4</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
我真的希望能够在 environmentProperties 文件夹中拥有尽可能多的属性文件,然后更新 web.xml(和 context.xml)文件以为每个环境添加适当的条目。这可能吗?
我见过 Apache Velocity 做循环结构,但不知道是否有 Maven 插件可以让我使用它。
谢谢, 保罗
【问题讨论】:
标签: java maven-3 maven-plugin velocity maven-resources-plugin