繁体   English   中英

基于Maven配置文件的context.xml中的JNDI配置

[英]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
  • 使用自定义maven属性替换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>
  • 激活maven构建中的相应配置文件。 例如,在命令行上调用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM