Tomcat替换VM参数 [英] Tomcat Replacing VM arguments

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

问题描述

这可能是一个愚蠢的问题:

this may be a stupid question:

我目前有一些我的Web应用程序需要的VM参数。它们类似于:

I currently have some VM arguments that my web application requires. They are something like:

-Dcom.company.custom.var='test'

我在代码中访问它们:

System.getProperty("com.company.custom.config")

我想搬家他们进入了一个tomcat xml文件(server.xml,context.xml等),但我不确定如何做到这一点。

I would like to move them into one of the tomcat xml files (server.xml, context.xml, etc) but I'm not sure how I would go about doing that.

所以我的问题是两部分。我应该在哪里(以及如何)将这些变量放入xml中,如何在代码中访问它们?

So my question is two parts. Where (and how) should I put these variables into xml and how do I access them in code?

如果这已经得到解答,请提前致谢并对不起。我对这个主题的搜索失败了。

Thanks in advance and sorry if this has already been answered. My search-fu on this topic has failed me.

推荐答案

正式地,所有JVM选项都转到 setenv.sh (对于Unix)或 setenv.bat (对于Windows)。此文件在Tomcat中默认不存在,但如果你创建一个,它将被启动脚本选中。

Officially, all JVM options go either to setenv.sh (for Unix) or setenv.bat (for Windows). This file is not present by default in Tomcat but if you create one, it will be picked up by startup script.

你应该使用它而不是 server.xml server.xml 可能会从一个Tomcat版本更改为另一个但是 setenv.sh (或。 bat)是完全自定义的。

The reason why you should be using this instead of server.xml is that server.xml might change from one Tomcat version to another but setenv.sh (or .bat) is completely custom to you.

正如你所指出的,读取这个值是通过 System.getProperty(...)

Reading this value is, as you pointed out, through System.getProperty(...).

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

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