プロパティファイルの値に基づいて、私のcontext.xmlおよびweb.xmlファイルの内容を更新したいと思います。 Webアプリケーションで使用できるデータベース接続を設定したい。このコンテンツを動的に追加することは可能ですか?私は現在、いくつかの更新は私がMaven Pluginを使用してファイルコンテンツを更新できますか?
<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>
次している私の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>
で次のビルドセクションを使用して起こっている
は、私が本当にできることを好むだろうenvironmentPropertiesフォルダに必要な数のプロパティファイルを作成し、web.xml(およびcontext.xml)ファイルを更新して各環境に適切なエントリを追加します。これは可能ですか?
私はApache Velocityのループ構造を見ましたが、これを利用できるようにするMavenプラグインがあるかどうかはわかりません。
おかげで、 ポール
私に戻ってくれてありがとう。私が現在持っているアプローチは、フィルタセクションにエントリを追加することによってプロパティファイルから値を読み取ることができるようにすることです。ただし、フォルダ(src/main/resources/environmentProperties)を指定してMavenのワークアウトを行い、すべてのファイルを読み込むことをお勧めします。別のファイルが追加された場合、POMを変更する必要はありません。また、プロパティファイルの数に基づいてweb.xmlとcontext.xml内に正しい数のエントリを作成することを決定したいと思っています。これは、テンプレートを特定する際に何らかのループを伴います。 – ceepan
StringTemplateのWebサイトを見てみましょう。これはテンプレートエンジンであり、必要な処理を行います。 http://www.stringtemplate.org/ - また、私はプロパティプラグインはワイルドカードを取ることができると思うが、確かに複数のファイルを取るだろう。 – mikeb