42

I have installed tomcat7 (using apt-get install) and whenever I want to start tomcat7 it says :

* no JDK found - please set JAVA_HOME

I have set JAVA_HOME in my bash.bashrc and also in ~/.bashrc and when I issue echo $JAVA_HOME I clearly see that this variable is pointing to my jdk's root folder. Can someone help me with this please?

Thanks

icedwater
  • 150
  • 11
Hossein
  • 1,677
  • 3
  • 16
  • 10

5 Answers5

80

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.

mac
  • 3,801
  • 4
  • 35
  • 50
Mitch
  • 106,657
  • 24
  • 210
  • 268
  • Note that upgrading to JDK 7 will break this answer. Using a symbolic link without the version number will allow upgrades without invalidating environment variables. – Dave Jarvis Oct 24 '14 at 19:14
  • 1
    Also works for `tomcat8`, just replace `tomcat7` strings by `tomcat8`. – nachtigall Mar 09 '17 at 11:04
9

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
djjeck
  • 191
  • 1
  • 3
5

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.

Zanna
  • 69,223
  • 56
  • 216
  • 327
2

Just add following line in /etc/default/tomcat7 at where JAVA_HOME variable is defined

JAVA_HOME=/usr/lib/jvm/java-7-oracle

then run command

sudo service tomcat7 restart
Eric Carvalho
  • 53,609
  • 102
  • 137
  • 162
user249933
  • 29
  • 1
0

Adding to the answer of Mitch (the accepted answer above), check your /usr/lib/jvm/ directory. Usually, java is installed there itself.

You might have oracle java installed or you might have a latest version of java installed. Just checkout the directories at /usr/lib/jvm/ and add the one your java is in.

For me, it was:

/usr/lib/jvm/java-8-oracle

So, replace

#JAVA_HOME=/some/directory

with

#JAVA_HOME=/usr/lib/jvm/java-8-oracle

did the job for me.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Akeshwar Jha
  • 101
  • 5