How do I pass a system property to a web application hosted on Tomcat 7 running as a Windows service?

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

  • via CATALINA_OPTS
  • via JAVA_OPTS
  • in TOMCAT_OPTS
  • by putting set statements in the setenv.bat file inside the tomcat bin folder

My problem is that I tried all of the above and my web application still does not see my system property!

That's what I'm 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 completely redundant, but just in case)
  • Start tomcat7 service
  • Inspect the tomcat7 process environment using the Process Explorer tool - the environment is correct, I see that both CATALINA_OPTS and JAVA_OPTS and TOMCAT_OPTS are equal to -Dabc.def=true
  • run my web application, which is a simple servlet that dumps all system properties into the response stream - abc.def not among

Please take me out of my misery and tell me how to do it.

+4
source share
1 answer

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

HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun 2.0\Tomcat<X>\Parameters\Java

(if necessary, replace the appropriate version of Tomcat).

Edit:

On a 64-bit version of Windows, the registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\Tomcat<X>\Parameters\Java

even if Tomcat runs on a 64-bit JVM.

+10
source

Source: https://habr.com/ru/post/1387644/


All Articles