如何将系统属性传递给作为Windows服务运行的Tomcat 7中托管的Web应用程序?
互联网上有很多地方,建议通过以下任何(或全部)方法轻松实现:
There are numerous places on the Internet, suggesting that it is easily achieved by any (or all) of the following methods:
- 通过
CATALINA_OPTS
- 通过
JAVA_OPTS
- 通过
TOMCAT_OPTS
- 在 set 语句> tomten的bin文件夹中的> setenv.bat 文件
- through
CATALINA_OPTS
- through
JAVA_OPTS
- through
TOMCAT_OPTS
- by placing the
set
statements in the setenv.bat file inside the tomcat's bin folder
我的问题是,我已经尝试了以上所有内容我的网络应用程序仍然没有看到我的系统属性!
My problem, is that I have tried all of the above and my web application still does not see my system property!
这是我正在做的事情:
- 停止tomcat7服务
- 在系统环境中设置
CATALINA_OPTS = -Dabc.def = true
- 在系统环境中设置
JAVA_OPTS = -Dabc.def = true
- 设置
系统环境中的TOMCAT_OPTS = -Dabc.def = true
- 将以上所有内容放入 c:\Program Files \ ApachePache Foundation \ Tomcat 7.0 \\\\\ entenv.bat (似乎完全多余,但以防万一)
- 启动tomcat7服务
- 使用Process Explorer工具检查tomcat7进程的环境 - 环境是正确的,我确实看到
CATALINA_OPTS
和JAVA_OPTS
和TOMCAT_OPTS
等于-Dabc.def = true
- run我的网络应用程序,这是一个简单的servlet,将所有系统属性转储到响应流 -
abc.def
不在其中
- 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
请让我摆脱痛苦,告诉我该怎么做。
Please, put me out of my misery and tell me how to do it.
对于Tomcat服务,启动设置存储在注册表中的选项
键下:
For the Tomcat service, startup settings are stored in the registry under Options
key at:
HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation \Procrun 2.0 \ Tomcat< X> \Parameters\Java
(替换approp在需要的地方使用Tomcat版本。
(substitute appropriate Tomcat version where needed).
编辑:
在64位Windows上,注册表项是:
On 64-bit Windows, the registry key is:
HKEY_LOCAL_MACHINE\SOFTWARE \Wow6432Node\Apache Software Foundation \Procrun 2.0 \ Tomcat< X> \Parameters\Java
即使Tomcat在64位JVM下运行。
even if Tomcat is running under a 64-bit JVM.