1. Overview
In this tutorial, we’re going to see to how set up environment variables for applications deployed in Apache Tomcat.
1. Set up Environment Variables For Apache Tomcat On Windows
One popular approach to set up environment variables for Apache Tomcat runs on Windows is to use an additional file called setenv.bat, and put the variables as pairs of key and value in the file. For example, let’s set JAVA_HOME and JAVA_OPTS for the Tomcat step by step as follows:
- Create a file setenv.bat in the CATALINA_HOME /bin
- Open the file with a text editor and put the following lines to the file:
1 2 |
set JAVA_HOME=PATH TO YOUR JDK set JAVA_OPTS=-Xms1G -Xmx1G |
Note that there is no Quotation Marks required for setting up environment for Apache Tomcat on Windows, and the file will be called automatically when the Tomcat is startup.
2. Set up Environment Variables For Apache Tomcat On Linux
On Linux, to set up environment variables for Apache Tomcat, we can do the same approach with Windows’s. However, the file should be setenv.sh. Let’s set the same JAVA_HOME and JAVA_OPTS variables on Linux:
- Create a file setenv.sh in the folder CATALINA_HOME /bin
- Open the file and put the following lines to the file:
1 2 |
export JAVA_HOME="PATH TO YOUR JDK" export JAVA_OPTS="-Xms1G -Xmx1G" |
Note that for Linux environment, the quotation marks are required, and the file will be called automatically when the Tomcat is started.
3. Environment Variables Can Be Set In CATALINA_HOME/bin/setenv.sh
As stated in CATALINA_HOME /bin/catalina.sh, catalina.bat files the following environment variables can be set in CATALINA_HOME /bin/setenv.sh, catalina.bat. The setenv.bat and setenv.sh script are run on Tomcat startup. They are not present in standard Tomcat distribution, so they have to be created.
Variable Names | Descriptions | ||
CATALINA_HOME | Represents the root of your Tomcat installation | ||
CATALINA_BASE | May point at your Catalina “build” directory | ||
CATALINA_OUT | Full path to a file where stdout and stderr will be redirected. | ||
CATALINA_OPTS | Java runtime options used when the “start” or “run” command is executed | ||
CATALINA_TMPDIR | Directory path location of temporary directory the JVM should use (java.io.tmpdir) | ||
JAVA_HOME | Must point at your Java Development Kit installation | ||
JRE_HOME | Must point at your Java Runtime installation.Defaults to JAVA_HOME if empty | ||
JAVA_OPTS | Java runtime options used when the “start”, “stop” or “run” command is executed | ||
JAVA_ENDORSED_DIRS | Lists of of colon separated directories containing some jars in order to allow replacement of APIs created outside of the JCP (i.e. DOM and SAX from W3C). It can also be used to update the XML parser implementation. Defaults to $CATALINA_HOME/endorsed. | ||
JPDA_TRANSPORT | JPDA transport used when the “jpda start” command is executed. The default is “dt_socket”. | ||
JPDA_ADDRESS | Java runtime options used when the “jpda start” command is executed. The default is 8000. | ||
JPDA_SUSPEND | Java runtime options used when the “jpda start” command is executed. Specifies whether JVM should suspend execution immediately after startup. Default is “n”. | ||
JPDA_OPTS | Java runtime options used when the “jpda start” command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS, and JPDA_SUSPEND are ignored. Thus, all required jpda options MUST be specified. The default is: -agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND | ||
CATALINA_PID | Path of the file which should contains the pid of the catalina startup java process, when start (fork) is used | ||
LOGGING_CONFIG | Override Tomcat’s logging config file Example (all one line) | ||
LOGGING_MANAGER | Override Tomcat’s logging managerExample (all one line) | ||