This article describes few useful bits and pieces about running Apache Tomcat.

Setup of Tomcat environment variables –

As stated in CATALINA_BASE/bin/ file the following environment variables can be set in CATALINA_BASE/bin/ . script is run on Tomcat startup. It is not present in standard Tomcat distribution, so has to be created.

  • CATALINA_HOME May point at your Catalina “build” directory.
  • CATALINA_BASE (Optional) Base directory for resolving dynamic portions of a Catalina installation. If not present, resolves to the same directory that CATALINA_HOME points to.
  • CATALINA_OUT (Optional) Full path to a file where stdout and stderr will be redirected. Default is $CATALINA_BASE/logs/catalina.out
  • CATALINA_OPTS (Optional) Java runtime options used when the “start”, “run” or “debug” command is executed. Include here and not in JAVA_OPTS all options, that should only be used by Tomcat itself, not by the stop process, the version command etc. Examples are heap size, GC logging, JMX ports etc.
  • CATALINA_TMPDIR (Optional) Directory path location of temporary directory the JVM should use ( Defaults to $CATALINA_BASE/temp.
  • JAVA_HOME Must point at your Java Development Kit installation. Required to run the with the “debug” argument.
  • JRE_HOME Must point at your Java Runtime installation.Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME are both set, JRE_HOME is used.
  • JAVA_OPTS (Optional) Java runtime options used when any command is executed.Include here and not in CATALINA_OPTS all options, that should be used by Tomcat and also by the stop process, the version command etc. Most options should go into CATALINA_OPTS.
  • JAVA_ENDORSED_DIRS (Optional) 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 (Optional) JPDA transport used when the “jpda start” command is executed. The default is “dt_socket”.
  • JPDA_ADDRESS (Optional) Java runtime options used when the “jpda start” command is executed. The default is 8000.
  • JPDA_SUSPEND (Optional) 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 (Optional) 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:
  • CATALINA_PID (Optional) Path of the file which should contains the pid of the catalina startup java process, when start (fork) is used
  • LOGGING_CONFIG (Optional) Override Tomcat’s logging config file Example (all one line) LOGGING_CONFIG=”-Djava.util.logging.config.file=$CATALINA_BASE/conf/
  • LOGGING_MANAGER (Optional) Override Tomcat’s logging managerExample (all one line)
  • LOGGING_MANAGER=-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager”

In case you need more memory to run your Tomcat instance just put the following line in file.

export JAVA_OPTS="-XX:MaxPermSize=1024m -Xms512m -Xmx4096m"

Running Tomcat – start|run|debug|jpda start

To run Tomcat you can use script with different options:

  • start: The Tomcat process is started in its own shell/session. Instead of that command you can run:
  • run: The Tomcat process is started in current shell/session, the startup process output will be printed on the console, and the execution will be stopped on session close or on ctrl+c.
  • debug: The Tomcat starts under jdb – The Java Debugger.
  • jpda start: The Tomcat runs with remote debugging support.

For more details see JPDA_* variables above and Remote debugging of web application deployed on Tomcat server or using Jetty Maven plugin with Eclipse.