从.war文件外部化Tomcat webapp配置

编程入门 行业动态 更新时间:2024-10-14 20:25:21
本文介绍了从.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配置

本文发布于:2023-11-25 20:42:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631277.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   war   webapp   Tomcat

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!