基于Maven配置文件的context.xml中的JNDI配置 [英] JNDI Configuration in context.xml based on Maven profile

查看:220
本文介绍了基于Maven配置文件的context.xml中的JNDI配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于



我很想和maven一起做时髦的东西而且我遇到了困境。我有两个需要部署的独立服务器,每个服务器都是一个稍微不同的JDNI资源配置文件,如 context.xml中所定义



我的文件结构是这样的:(虽然如果有更好的方式我可以改变它

  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 file。



问题



我理解我需要设置两个不同的构建配置文件,例如:

 < profiles> 
< profile>
< id> prod< / id>
< / profile>
< profile>
< id> devel< / id>
< / profile>
< / profiles>

但是从这里我对最好的解决方案感到困惑。我理解使用war插件我可以排除 context.xml 但是从那时起我很困惑该怎么做。



是否只有一种方法可以在我的 context.xml 中包含一个变量,我可以使用mavenwrite而不是拥有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>





< pre class =lang-xml prettyprint-override> < 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


Given

I'm new to doing "funky stuff" with maven and I've run into a quandary. I have two separate servers I need to deploy to and each as a slightly different JDNI resource profile as defined in context.xml

My file structure is as such: (although i can change this if there is a better way)

src/main/webapp/META-INF/context.xml
src/main/webapp/META-INF/context.devel.xml
src/main/webapp/META-INF/context.prod.xml

Depending on the deployment target I would like to use the appropriate context.TARGET.xml file.

Question

I understand I would need to setup two different build profiles such as:

<profiles>
  <profile>
      <id>prod</id>
  </profile>
  <profile>
    <id>devel</id>
  </profile>
</profiles> 

but from here I get confused as to what the best solution is. I understand with the war plugin I can exclude context.xml but from that point onwards i'm confused what to do.

Is there just a way to have a variable inside of my context.xml that i can have maven "write" as opposed to having 2 different configuration files.

Any suggestions?

解决方案

Here are some hints.

  • you need only one context.xml .
  • replace the server specific entries in context.xml with custom maven properties. For example: ${myServer} or ${dbUser}
  • define these properties in your profiles like this

<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>

  • activate the appropriate profile within the maven build. For example, call mvn -Pprod clean package on the command line. Or activate the needed profile in your IDE. For devl use -Pdevl instead.

这篇关于基于Maven配置文件的context.xml中的JNDI配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆