[英]JNDI Configuration in context.xml based on Maven profile
我很想和maven一起做“時髦的東西”而且我遇到了困境。 我有兩個需要部署的獨立服務器,每個服務器都是context.xml
定義的稍微不同的JDNI資源配置文件
我的文件結構是這樣的:( 雖然如果有更好的方法,我可以改變它 )
src/main/webapp/META-INF/context.xml
src/main/webapp/META-INF/context.devel.xml
src/main/webapp/META-INF/context.prod.xml
根據部署目標,我想使用適當的context.TARGET.xml
文件。
我知道我需要設置兩個不同的構建配置文件,例如:
<profiles>
<profile>
<id>prod</id>
</profile>
<profile>
<id>devel</id>
</profile>
</profiles>
但是從這里我對最好的解決方案感到困惑。 我理解使用war插件我可以排除context.xml
但是context.xml
起我就很困惑該做什么。
有沒有辦法在我的context.xml
中有一個變量,我可以使用maven“write”而不是擁有2個不同的配置文件。
有什么建議?
這里有一些提示。
context.xml
。 context.xml
的服務器特定條目。 例如:$ {myServer}或$ {dbUser} <profiles>
<profile>
<id>prod</id>
<properties>
<myServer>srv-prod.yourcompany.com</myServer>
<dbUser>james</dbUser>
</properties>
</profile>
<profile>
<id>devel</id>
<properties>
<myServer>srv-devel.yourcompany.com</myServer>
<dbUser>richard</dbUser>
</properties>
</profile>
</profiles>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
<webResources>
<resource>
<directory>src/main/webapp/META-INF</directory>
<targetPath>/META-INF</targetPath>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
mvn -Pprod clean package
。 或者在IDE中激活所需的配置文件。 對於devl
使用-Pdevl
。 您可以使用maven資源過濾從Maven構建生命周期的進程資源階段顯式包含或排除特定文件。
<profiles>
<profile>
<id>prod</id>
<resources>
<resource>
<directory>src/main/resources/META-INF</directory>
<filtering>true</filtering>
<includes>
<include>**/context.prod.xml</include>
</includes>
</resource>
</resources>
</profile>
<profile>
<id>devel</id>
<resources>
<resource>
<directory>src/main/resources/META-INF</directory>
<filtering>true</filtering>
<includes>
<include>**/context.devl.xml</include>
</includes>
</resource>
</resources>
</profile>
</profiles>
文檔可以在這里找到。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.