How to set JAVA_HOME or CATALINA_HOME if I have more than 1 version used for Projects?
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 CAT开发者_如何学CALINA_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...).
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 applicationsCATALINA_HOME
is the path of the tomcat binaries filesCATALINA_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
If you are running it with in Eclipse, you can use the Run Configuration dialog to set any enviornment variables that you need to change. These get automatically set when you execute the specified Run configuration. To use this, Right Click on your project, select Run -> Run Configurations. In that you can select a Run Configuration, and goto the Environment tab, and there you can specify the custom variables you want, and also you can override anything that is set by the O/S.
If you want to do this outside eclipse, and you keep a copy of Tomcat dedicated for each project, edit the startup.sh or startup.bat files depending on your OS and then set the environemnt variables explicitly there.
Ex. For Project 1:, on top of /opt/apache-tomcat6-1/bin/startup.sh file add these lines
export JAVA_HOME='/opt/jdk1' export JAVA_HOME='/opt/apache-tomcat6-1'
Ex. For Project 2:, on top of /opt/apache-tomcat6-2/bin/startup.sh file add these lines
export JAVA_HOME='/opt/jdk2' export JAVA_HOME='/opt/apache-tomcat6-2'
If you don't have a dedicated copy of Tomcat, then you can create a shell script / batch file per project which will set the necessary environment variables like this and then invoke the corresponding startup.sh or startup.bat file.
These variables are used by the scripts that start Tomcat, and don't matter otherwise. You can set them immediately before running the startup.sh
script, or you can edit the catalina.sh
script to set the values in the script itself (this is a good way to do it, since catalina.sh
is shared by the other scripts), or you can write your own scripts which set the variables and then call the tomcat scripts... There are many possibilities. You just can't set the variables globally.
精彩评论