Tomcat 7 with Java 8 on Windows and Linux Tomcat 7 with Java 8 on Windows and Linux linux linux

Tomcat 7 with Java 8 on Windows and Linux


Thank you, everyone, I found what happened. It turned out that JAVA_HOME was not defined in a proper way (as logoff and Marko Topolnik mentioned). I opened /etc/default/tomcat7 and changed this section:

# The home directory of the Java development kit (JDK). You need at least# JDK version 6. If JAVA_HOME is not set, some common directories for# OpenJDK, the Oracle JDK, and various Java SE 6+ versions are tried.#JAVA_HOME=/usr/lib/jvm/openjdk-6-jdkJAVA_HOME=/path/to/my/jdk

... and everything starts to work! Does Tomcat really use an internal JDK smth like OpenJDK by default?


Each Tomcat instance uses by default the default JDK on the machine.You either change the default JDK (if you use one Tomcat instance), or tell Tomcat to use a different JDK.

  1. For setting a different JDK for each TOMCAT instance:

catalina.sh calls setenv.sh for using a JDK. Create file setenv.sh in CATALINA_BASE/bin, if not exists. CATALINA_BASE stands for the Tomcat folder. Open setenv.sh with gedit:

sudo gedit setenv.sh

write this line:

export JAVA_HOME=/path/to/your/JDK

Tomcat recommends exporting JAVA_HOME in setenv.sh, not in catalina.sh.

  1. For changing the default JDK on Ubuntu:

    sudo update-alternatives --install /your/path/to/JDK/bin/java

or:

sudo update-alternative --install  ${JAVA_HOME}/bin/java

if you have JAVA_HOME defined.


The JAVA_HOME environment variable is irrelevant to how Eclipse will run code. Likewise the compiler settings you've shown for a project don't affect how code is run.

Instead, you need to look at the Run Configuration you are using and check the environment there. Make sure you're using Java 8, and all should be well. Click on the triangle next to the Run button, and select "Run Configurations..." to open the dialog with all the settings. Then look at the JRE tab, and ensure you're using the right JRE.