如何将系统属性传递给作为Windows服务运行的Tomcat 7中托管的Web应用程序?

如何将系统属性传递给作为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:


  1. 通过 CATALINA_OPTS

  2. 通过 JAVA_OPTS

  3. 通过 TOMCAT_OPTS

  4. set 语句> tomten的bin文件夹中的> setenv.bat 文件

  1. through CATALINA_OPTS
  2. through JAVA_OPTS
  3. through TOMCAT_OPTS
  4. 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!

这是我正在做的事情:


  1. 停止tomcat7服务

  2. 在系统环境中设置 CATALINA_OPTS = -Dabc.def = true

  3. 在系统环境中设置 JAVA_OPTS = -Dabc.def = true

  4. 设置系统环境中的TOMCAT_OPTS = -Dabc.def = true

  5. 将以上所有内容放入 c:\Program Files \ ApachePache Foundation \ Tomcat 7.0 \\\\\ entenv.bat (似乎完全多余,但以防万一)

  6. 启动tomcat7服务

  7. 使用Process Explorer工具检查tomcat7进程的环境 - 环境是正确的,我确实看到 CATALINA_OPTS JAVA_OPTS TOMCAT_OPTS 等于 -Dabc.def = true

  8. run我的网络应用程序,这是一个简单的servlet,将所有系统属性转储到响应流 - abc.def 不在其中

  1. Stop tomcat7 service
  2. set CATALINA_OPTS=-Dabc.def=true in the system environment
  3. set JAVA_OPTS=-Dabc.def=true in the system environment
  4. set TOMCAT_OPTS=-Dabc.def=true in the system environment
  5. 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)
  6. Start tomcat7 service
  7. Inspect the environment of the tomcat7 process using the Process Explorer tool - the environment is correct, I do see both CATALINA_OPTS and JAVA_OPTS and TOMCAT_OPTS equal to -Dabc.def=true
  8. 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.