Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CATALINA_OPTS vs JAVA_OPTS - What is the difference?

I was trying to find out the difference between Apache Tomcat variables - CATALINA_OPTS and JAVA_OPTS in SO and surprised to see that there is no question/answer posted here yet. So I thought of sharing it here (with answer) after finding out the difference. Check the answer/difference below.

NOTE: At the time of this posting, we're running Apache Tomcat v6.0.10 with JDK 6u32 on CentOS5 64-bit arch.

like image 936
Gnanam Avatar asked Jun 27 '12 08:06

Gnanam


People also ask

What is Catalina_opts?

The CATALINA_OPTS environment variable is used to pass configuration flags and system properties to the JVM that runs the Tomcat server. Tomcat recommends using a setenv script to specify environment variables.

What is JAVA_OPTS?

JAVA_OPTS is an environment variable that you can set to pass custom settings to the Java Virtual Machine (JVM) that runs Liquibase.

Where is Catalina_opts?

On Unix® and Linux® systems: You can set the JVM heap size by specifying CATALINA_OPTS settings in the setenv.sh file (typically located in the /tomcat/bin/ directory). If this file doesn't exist, you should create it in the same directory as the catalina.sh file (also typically located in the /tomcat/bin/ directory).


1 Answers

There are two environment variables - CATALINA_OPTS and JAVA_OPTS - which are both used in the catalina.sh startup and shutdown script for Tomcat. They are described in comments within that file as:

[JAVA_OPTS]: (optional) Java runtime options used when the "start", "stop" or "run" command is executed

and

[CATALINA_OPTS]: (optional) Java runtime options used when the "start" or "run" command is executed

So why are there two different variables? And what's the difference?

Firstly, anything specified in EITHER variable is passed, identically, to the command that starts up Tomcat - the "start" or "run" command - but only values set in JAVA_OPTS are passed to the "stop" command. That probably doesn't make any difference to how Tomcat runs in practise as it only effects the end of a run, not the start.

The second difference is more subtle. Other applications may also use JAVA_OPTS, but only Tomcat will use CATALINA_OPTS. So if you're setting environment variables for use only by Tomcat, you'll be best advised to use CATALINA_OPTS, whereas if you're setting environment variables to be used by other java applications as well, such as by JBoss, you should put your settings in JAVA_OPTS.

Source: CATALINA_OPTS v JAVA_OPTS - What is the difference?

like image 62
Gnanam Avatar answered Nov 02 '22 22:11

Gnanam