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
statements in the setenv.bat file inside the tomcat's bin folderMy 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:
CATALINA_OPTS=-Dabc.def=true
in the system environmentJAVA_OPTS=-Dabc.def=true
in the system environmentTOMCAT_OPTS=-Dabc.def=true
in the system environmentCATALINA_OPTS
and JAVA_OPTS
and TOMCAT_OPTS
equal to -Dabc.def=true
abc.def
is not amongst them
Please, put me out of my misery and tell me how to do it.
To install an instance, first set the CATALINA_HOME environment variable to the name of the Tomcat installation directory. Then create a second environment variable CATALINA_BASE and point this to the instance folder. Then run "service. bat install" command specifying a service name.
1) Open a command prompt, go to the bin folder of the apache tomcat and run "service. bat install". If the CATALINA_HOME, JAVA_HOME and JRE_HOME are correctly configured, the 'Tomcat' service will be installed successfully.
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
(substitute appropriate Tomcat version where needed).
Edit:
On 64-bit Windows, the registry key is:
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.
I know this post is almost 9 years old but thought someone might find this useful.
Although @prunge and @mark answers were very accurate and following their logic I was able to add system properties to my tomcat 7 instance running on Windows, there is an easier way.
In the installation directory of Tomcat there is an exe you can run called
%INSTALL_DIRECTORY%\bin\tomcat7w.exe
This opens up a Tomcat properties windows where you can control the service i.e. start and stop tomcat and there is a tab (Java) that allows you to set the Java properties as well
Scroll to the end of that panel under "Java Options" and add your system properties
-Dpropertyname=value
Then navigate back to the General tab and restart tomcat
I have tested this and my grails app now can see my properties. I use the following Groovy code to get the property out
System.properties.getProperty("propertyname")
Adding the system properties in the Windows registry showed up in this window as well so its one and the same thing, just this application seems to me to be slightly more convenient.
Hope this helps someone else
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With