Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set JAVA_HOME or CATALINA_HOME if I have more than 1 version used for Projects?

Tags:

java

tomcat

I have different projects using different version of JDK (5.0, 6.0) and Tomcat(6.0, 7.0), so how should my JAVA_HOME and CATALINA_HOME be set in environment variables?

Or maybe it is NOT necessary to set JAVA_HOME and CATALINA_HOME in environment variables if I am running my App by .War file? The jdk/tomcat server will be running the version I picked when I packed it (through Eclipse -> preferences...).

like image 387
sharon Avatar asked May 30 '11 04:05

sharon


1 Answers

Inside the tomcat startup script /bin/catalina.sh, the following environmental variables are used:

  • JAVA_HOME is the path of JDK that used to run the tomcat and web applications
  • CATALINA_HOME is the path of the tomcat binaries files
  • CATALINA_BASE is the path the tomcat configuration files

So , how about this approach? For example :

Install JDK 5.0 to : /opt/jdk5
Install JDK 6.0 to : /opt/jdk6
Install tomcat 6.0 to :/opt/tomcat6
Install tomcat 7.0 to : /opt/tomcat7

Each of your web application has their own folder to hold their own tomcat 's configuration. For example : /home/web1 for the web application 1
/home/web2 for the web application 2

Inside each of these folders , we need the following sub directories: conf, logs, temp, webapps, and work.Simply copy these sub directories from the tomcat installation folder (ie. /opt/tomcat7/) .Then put the .war to the corresponding webapps folders (e.g. /home/web1/webapps/webappl.war , /home/web2/webapps/webapp2.war ).

Finally , write a script to start the tomcat using different JDK and tomcat for each application . For example , to start web1, your script should look likes:

JAVA_HOME=/path/to/jdk  #eg./opt/jdk6 
CATALINA_HOME=/path/to/tomcat/installation #eg./opt/tomcat7 
CATALINA_BASE=/home/web1/
export JAVA_HOME JAVA_OPTS CATALINA_HOME CATALINA_BASE
$CATALINA_HOME/bin/catalina.sh start

Reference : http://www.mohancheema.net/appserver/setting-tomcat-to-run-mutiple-instances-of-it

like image 128
Ken Chan Avatar answered Sep 28 '22 15:09

Ken Chan