如何将系统属性传递给托管在作为 Windows 服务运行的 Tomcat 7 中的 Web 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8609998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pass a system property to a web application hosted in Tomcat 7 running as a Windows Service?
提问by mark
There are numerous places on the Internet, suggesting that it is easily achieved by any (or all) of the following methods:
网上有很多地方,建议可以通过以下任何一种(或全部)方法轻松实现:
- through
CATALINA_OPTS
- through
JAVA_OPTS
- through
TOMCAT_OPTS
- by placing the
set
statements in the setenv.batfile inside the tomcat's bin folder
- 通过
CATALINA_OPTS
- 通过
JAVA_OPTS
- 通过
TOMCAT_OPTS
- 通过将
set
语句放在 tomcat 的 bin 文件夹内的setenv.bat文件中
My problem, is that I have tried all of the above and my web application still does not see my system property!
我的问题是,我已经尝试了上述所有方法,但我的 Web 应用程序仍然看不到我的系统属性!
Here is what I am doing:
这是我在做什么:
- Stop tomcat7 service
- set
CATALINA_OPTS=-Dabc.def=true
in the system environment - set
JAVA_OPTS=-Dabc.def=true
in the system environment - set
TOMCAT_OPTS=-Dabc.def=true
in the system environment - put all of the above into c:\Program Files\Apache Software Foundation\Tomcat 7.0\bin\setenv.bat(seems totally redundant, but just in case)
- Start tomcat7 service
- Inspect the environment of the tomcat7 process using the Process Explorer tool - the environment is correct, I do see both
CATALINA_OPTS
andJAVA_OPTS
andTOMCAT_OPTS
equal to-Dabc.def=true
- run my web app, which is a simple servlet dumping all the system properties to the response stream -
abc.def
is not amongst them
- 停止tomcat7服务
CATALINA_OPTS=-Dabc.def=true
在系统环境中设置JAVA_OPTS=-Dabc.def=true
在系统环境中设置TOMCAT_OPTS=-Dabc.def=true
在系统环境中设置- 将上述所有内容放入c:\Program Files\Apache Software Foundation\Tomcat 7.0\bin\setenv.bat(似乎完全多余,但以防万一)
- 启动tomcat7服务
- 使用 Process Explorer 工具检查 tomcat7 进程的环境 - 环境是正确的,我确实看到了
CATALINA_OPTS
andJAVA_OPTS
和TOMCAT_OPTS
equal to-Dabc.def=true
- 运行我的 web 应用程序,这是一个简单的 servlet,将所有系统属性转储到响应流 -
abc.def
不在其中
Please, put me out of my misery and tell me how to do it.
请让我摆脱痛苦,告诉我该怎么做。
回答by prunge
For the Tomcat service, startup settings are stored in the registry under Options
key at:
对于 Tomcat 服务,启动设置存储在注册表下的注册表Options
项中:
HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun 2.0\Tomcat<X>\Parameters\Java
HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun 2.0\Tomcat<X>\Parameters\Java
(substitute appropriate Tomcat version where needed).
(在需要时替换适当的 Tomcat 版本)。
Edit:
编辑:
On 64-bit Windows, the registry key is:
在 64 位 Windows 上,注册表项是:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\Tomcat<X>\Parameters\Java
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\Tomcat<X>\Parameters\Java
even if Tomcat is running under a 64-bit JVM.
即使 Tomcat 在 64 位 JVM 下运行。