Specify JDK for tomcat7

Solution 1:

You can try this:

Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command below.

gksudo gedit /etc/default/tomcat7

When the file opens, uncomment the line that sets the JAVA_HOME variable.

enter image description here

Save and restart tomcat7 server.

Solution 2:

Tomcat will not actually use your JAVA_HOME environmente variable, but look in some predefined locations and in the JAVA_HOME variable set inside the startup script, as other answers point out. If you don't like messing with the tomcat startup script, you could create a symlink for your preferred java installation, which will be picked up by tomcat.

For example:

ln -s /usr/lib/jvm/java-8-oracle /usr/lib/jvm/default-java

Solution 3:

Open terminal

echo $JAVA_HOME

Copy the result. Then

sudo -H gedit /etc/default/tomcat7

Replace #JAVA_HOME=/usr/lib/jvm/openjdk-6-jdk with the output you copied from $JAVA_HOME.