通过VM参数到Apache Tomcat [英] Pass VM Argument to Apache Tomcat

查看:210
本文介绍了通过VM参数到Apache Tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有所谓的-Dfolder一个VM参数一个webProject

I have a webProject with a VM Argument called "-Dfolder"

我用的applicationContext这样的说法是这样的:

I use that argument on applicationContext like this:

<value>file:${FNET_CORE_CONFIG}/conf/${folder}/jdbc.properties</value>

在Eclipse中,进行测试,我使用运行配置这样设置值:

In Eclipse, for testing, i use "Run Configuration" to set the value like this:

-Dfolder=Dev

现在,我想测试我在Apache Tomcat Web应用程序,所以我需要设置/发送的文件夹VM参数。

Now, I want to test my webapp on Apache Tomcat so I need to set/send the folder VM Argument.

我怎么做到的?

我必须使用setenv.sh?怎么样?。有人可以给我和榜样?

I have to use setenv.sh? How?. Can someone give me and example?

谢谢,对不起,我的英语

Thanks and sorry for my english

推荐答案

我不知道你使用的是什么版本的Tomcat,但在Tomcat 7的文件catalina.sh您可以指定变量CATALINA_OPTS这个变量将传递给JVM 。

I don't know what version of Tomcat you using, but in Tomcat 7 in file catalina.sh you can specify variable CATALINA_OPTS and this variable will pass to jvm.

但也许设置环境变量是不是才达到你的目标一个最好的方式。也许最好的将是独立的app.properties文件的创建,以及包括它的applicationContext是这样的:

But maybe setting environment variable isn't a best way to achive your goal. Maybe best will be creation of separate "app.properties" file, and including it in applicationContext like this:

<context:property-placeholder location="classpath*:app.properties" />

和为catalina.sh解决方案

And solution for catalina.sh

#   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
#                   "run" or "debug" command is executed.
#                   Include here and not in JAVA_OPTS all options, that should
#                   only be used by Tomcat itself, not by the stop process,
#                   the version command etc.
#                   Examples are heap size, GC logging, JMX ports etc.

例如:

CATALINA_OPTS = - Dfolder =开发

CATALINA_OPTS="-Dfolder=Dev"

编辑:

有关窗口应该是这样的设置CATALINA_OPTS = - Dfolder =开发

for windows it should be something like set CATALINA_OPTS="-Dfolder=Dev"

编辑:

在Spring配置,您可以使用系统属性就像$ {PROPERTYNAME},并且还可以包括与属性定义文件,用背景:物业占位符,所有的定义在该文件的属性也配置成为avaliable。

In Spring configuration you can use system property just like ${propertyname}, and also can include file with property definition, with context:property-placeholder, and all defined in that file properties also become avaliable in config.

例如,你有基础的属性集:config.properties,并与数据库连接设置(DEV.properties,UAT.properties,PROD.properties)文件集。那么,你怎么可以包括不同的环境不同的属性?它可以做了很多办法,例如,在catalina.bat中设置系统属性。

For example, you have base set properties: config.properties, and set of files with db connection settings (DEV.properties, UAT.properties, PROD.properties). So, how can you include different properties for different environment? It can be done it many ways, for example, set system properties in catalina.bat

set CATALINA_OPTS="-Dbuild=DEV"

和在applicationConfig.xml

and in applicationConfig.xml

<context:property-placeholder location="classpath*:${build}.properties, classpath*:config.properties" />

或者你也可以创建不同的构建配置,包括仅在一个属性(DEV,UAT,PROD)为每个生成配置最后战争。在applicationConfig设置是这样的:

Or you can create different build configuration and include in final WAR only one properties (DEV, UAT, PROD) for each build configuration. In applicationConfig set something like:

<context:property-placeholder location="classpath*:*.properties" />

这篇关于通过VM参数到Apache Tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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