Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
289 views
in Technique[技术] by (71.8m points)

java - How to pass a system property to a web application hosted in Tomcat 7 running as a Windows Service?

There are numerous places on the Internet, suggesting that it is easily achieved by any (or all) of the following methods:

  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!

Here is what I am doing:

  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 FilesApache Software FoundationTomcat 7.0insetenv.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For the Tomcat service, startup settings are stored in the registry under Options key at:

HKEY_LOCAL_MACHINESOFTWAREApache Software FoundationProcrun 2.0Tomcat<X>ParametersJava

(substitute appropriate Tomcat version where needed).

Edit:

On 64-bit Windows, the registry key is:

HKEY_LOCAL_MACHINESOFTWAREWow6432NodeApache Software FoundationProcrun 2.0Tomcat<X>ParametersJava

even if Tomcat is running under a 64-bit JVM.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...