How to change Java version used by TOMCAT?
When you open catalina.sh / catalina.bat, you can see :
Environment Variable Prequisites
JAVA_HOME Must point at your Java Development Kit installation.
So, set your environment variable JAVA_HOME
to point to Java 6. Also make sure JRE_HOME
is pointing to the same target, if it is set.
Update: since you are on Windows, see here for how to manage your environment variables
You can change the JDK or JRE location using the following steps:
- open the terminal or cmd.
- go to the
[tomcat-home]\bin
directory.
ex:c:\tomcat8\bin
- write the following
command:
Tomcat8W //ES//Tomcat8
- will open dialog, select the java tab(top pane).
- change the Java virtual Machine value.
- click OK.
note:
in Apache TomEE same steps, but step (3) the command must be: TomEE //ES
If you use the standard scripts to launch Tomcat (i.e. you haven't installed Tomcat as a windows service), you can use the setenv.bat file, to set your JRE_HOME version.
On Windows, create the file
%CATALINA_BASE%\bin\setenv.bat
, with content:
set "JRE_HOME=%ProgramFiles%\Java\jre1.6.0_20"
exit /b 0
And that should be it.
You can test this using %CATALINA_BASE%\bin\configtest.bat (Disclaimer: I've only checked this with a Tomcat7 installation).
Further Reading:
- http://tomcat.apache.org/tomcat-5.5-doc/RUNNING.txt - Section: 'Advanced Configuration - Multiple Tomcat Instances'
- http://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt - Section: '(3.4) Using the "setenv" script (optional, recommended)'
In Eclipse it is very easy to point Tomcat to a new JVM (in this example JRE6). My problem was I couldn't find where to do it. Here is the trick:
- On the ECLIPSE top menu FILE pull down tab, select NEW, -->Other
- ...on the New Server: Select A Wizard window, select: Server-> Server... click NEXT
- . on the New Server: Define a New Server window, select Apache> Tomcat 7 Server
- ..now click the line in blue and underlined entitled: Configure Runtime Environments
- on the Server Runtime Environments window,
- ..select Apache, expand it(click on the arrow to the left), select TOMCAT v7.0, and click EDIT.
- you will see a window called EDIT SERVER RUNTIME ENVIRONMENT: TOMCAT SERVER
- On this screen there is a pulldown labeled JREs.
- You should find your JRE listed like JRE1.6.0.33. If not use the Installed JRE button.
- Select the desired JRE. Click the FINISH button.
- Gracefully exit, in the Server: Server Runtime Environments window, click OK
- in the New Server: Define a new Server window, hit NEXT
- in the New Server: Add and Remove Window, select apps and install them on the server.
- in the New Server: Add and Remove Window, click Finish
That's all. Interesting, only steps 7-10 seem to matter, and they will change the JRE used on all servers you have previously defined to use TOMCAT v7.0. The rest of the steps are just because I can't find any other way to get to the screen except by defining a new server. Does anyone else know an easier way?