You can define variables in setenv.sh
(Linux/UNIX) or setenv.bat
(Windows). Define the variables in the appropriate manner for the O/S you are running on. For Linux/UNIX you will need to export the variables. You can also define them in the environment you start Tomcat from.
You can also create an appenv.sh
or appenv.bat
file for application (local) changes. Read the existing setenv.sh
or setenv.bat
file for details.
Periods and hyphens are not valid for environment variables. Traditionally, the names are transformed by upper-casing the name and changing periods and hyphens to underscores. That would give the the name MY_SPECIAL_VARIABLE
. This would be defined with a line like:
export MY_SPECIAL_VARIABLE=some.value
You can also define Java system properties by adding a string '-Dmy.special.variable=some_valueto the command line used to start Tomcat. This is done in the same file. In
setenv.sh` you would add a line like:
export JAVA_OPTS="$JAVA_OPTS -Dmy.special.variable=some_value"
You can also use this file to tune the Java configuration. If JAVA_OPTS
system variable is defined in the environment used to launch Tomcat, its value will be added to the command line.
If you use a Java system property you retrieve with a call to System.getProperty
. This would be coded like:
System.getProperty("my.special.variable");