I have a server which uses Java 6 for an Oracle implementation. But I want to install a Tomcat Apache Server on it but with Java 8. So in order to not mix the system environment here's what I want to do:
-Get Apache Tomcat and JRE/JDK as zip formats. Extract them on a folder and tell my Apache Tomcar to use that JRE/JDK.
AFAIK. I can edit the JAVA_HOME and JAVA_JRE in the catalina.bat file and I am now trying it on a laptop. I set my catalina.bat file but when I try to run the apache server through command prompt I get the message "Neither the JAVA_HOME or JRE_HOME environment variables are defined(…)"
This is my catalina.bat file after I edited it.
echo Using CATALINA_BASE: "%CATALINA_BASE%"
echo Using CATALINA_HOME: "%CATALINA_HOME%"
echo Using CATALINA_TMPDIR: "%CATALINA_TMPDIR%"
if ""%1"" == ""debug"" goto use_jdk
echo Using JRE_HOME: "D:\ANDRES\Descargas\apache-tomcat-8.5.43-windows-x64\jre1.8.0_221\"
goto java_dir_displayed
:use_jdk
echo Using JAVA_HOME: "D:\ANDRES\Descargas\apache-tomcat-8.5.43-windows-x64\jdk1.8.0_221\"
:java_dir_displayed
echo Using CLASSPATH: "%CLASSPATH%"
So my question overall is. Is there a way to set the Tomcat server to use JRE_HOME from another route that is not defined on the system environment variables?
Best Answer
No need to modify
catalina.bat
. You can do that by setting the variables in thesetenv
script of your Tomcat installation. You seem to be using Windows, so here is an example of asetenv.bat
to changeJRE_HOME
andJAVA_HOME
.Create the file
%CATALINA_BASE%\bin\setenv.bat
with the following content:This way, only Tomcat will be affected by the change in variables, all other processes use
%PATH%
and system global variables as always.setenv
is described in the Tomcat docs, chapter 3.2