从.war文件外部化Tomcat webapp配置 [英] Externalizing Tomcat webapp config from .war file

查看:657
本文介绍了从.war文件外部化Tomcat webapp配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在tomcat中配置webapp 7.在我的war文件中,有一个属性文件myApp / WEB-INF / classes / myProps.props,它包含特定于环境的属性。我试图覆盖服务器上的配置文件,以便相同的war文件将部署到多个环境。

I am having trouble with configuring a webapp in tomcat 7. In my war file, there is a properties file myApp/WEB-INF/classes/myProps.props, and it contains environment-specific properites. I am trying to override that configuration file on the server, so that the same war file will deploy to multiple environments.

我听说有一个方法来做这个使用替换配置文件在tomcat / conf / Catalina / myApp。这是我无法找到的方法。

I heard there was a way to do this using replacement config files in tomcat/conf/Catalina/myApp. This is the method I am having trouble figuring out.

此外,myApp.war是许多运行在同一个tomcat服务器上的一个,它不作为localhost运行。我想要能够解决这个问题的几个webapps。

Also, myApp.war is one of many running on the same tomcat server, and it does not run as localhost. I want to be able to solve this problem for several of the webapps.

Server version: Apache Tomcat/7.0.23
Server built:   Nov 20 2011 07:36:25
Server number:  7.0.23.0
OS Name:        Linux


推荐答案

您的 tomcat / conf / Catalina /< host> 可以包含上下文描述符,您配置许多事情,包括定义环境条目,可以从Java通过JNDI访问。有很多方法可以使用它。就个人而言,我设置了一个环境条目,它是我的属性文件的文件系统路径。我的应用程序被构建来检查这个条目,如果它不存在,寻找类路径上的文件。这样,在dev中,我们在类路径上具有dev属性,但是当我们构建和部署时,我们将其指向一个外部文件。

Your tomcat/conf/Catalina/<host> can contain context descriptors that let you configure lots of things including defining "environment entries", which are accessible from Java via JNDI. There are lots of ways to go about using it. Personally, I set an environment entry which is the file system path to my properties file. My app is built to check for this entry, and if it doesn't exist, look for the file on the classpath instead. That way, in dev, we have the dev properties right there on the classpath, but when we build and deploy, we point it to an external file.

适用于Tomcat网站上的配置上下文

There's good documentation for configuring a context on the Tomcat website. See the "Defining a Context" section on details of how to create the file and where to put it.

例如,如果您的主机名称为myHost,并且您的主机名称为myHost您的应用程序是webapps目录中名为myApp.war的war文件,则可以使用此内容创建 tomcat / conf / Catalina / myHost / myApp.xml / p>

As an example, if your host is named "myHost" and your app is a war file named "myApp.war" in the webapps directory, then you could create tomcat/conf/Catalina/myHost/myApp.xml with this content:

<Context>
    <Environment name="configurationPath" value="/home/tomcat/myApp.properties" type="java.lang.String"/>
</Context>



< comp / env / configurationPath (这里有95%的确定性)来获取该字符串值。

Then from your code, you'd do a JNDI lookup on java:comp/env/configurationPath (95% certainty here) to get that string value.

这篇关于从.war文件外部化Tomcat webapp配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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