Omkar Shetkar
Omkar Shetkar

Reputation: 3636

Why JAVA_HOME not recognized by tomcat7 in Ubuntu?

I have installed tomcat7 on my Ubuntu machine. When I try to restart the server I get message to set JAVA_HOME but it is set in .bashrc

export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export CATALINA_HOME=/usr/share/tomcat7

Error:

omkars@<ubuntu_14.04>:~$ sudo service tomcat7 restart
[sudo] password for omkars: 
 * no JDK or JRE found - please set JAVA_HOME
omkars@<ubuntu_14.04>:~$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle

What could be missing ? Thanks.

Upvotes: 17

Views: 23513

Answers (7)

sentechno
sentechno

Reputation: 11

I have that same problem but I solve it by changing JDK_DIR variable in /etc/init.d/tomcat as follow :

JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-7-oracle /usr/lib/jvm/java-8-oracle"

Upvotes: 1

Omkar Shetkar
Omkar Shetkar

Reputation: 3636

Now, its working!

Changes I have done are:

  • changed .bashrc as explained in the question.
  • changed /etc/init.d/tomcat7 to point to oracle Java8 which is missing here!

    JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-7-oracle **/usr/lib/jvm/java-8-oracle**"
    

Then,

root@omkars-Dell-System-Inspiron-N4110:~# sudo service tomcat7 restart 
 * Starting Tomcat servlet engine tomcat7                                [ OK ] 

Got a hint from this page:
https://mifosforge.jira.com/wiki/display/MIFOSX/Install+Tomcat+7+on+Ubuntu+11.10+for+Mifos+X

Thanks

Upvotes: 28

Buzz Killington
Buzz Killington

Reputation: 1049

It seems like the preferred way of handling this is to uncomment the JAVA_HOME entry in /etc/default/tomcat7 and adjust the path accordingly. If you're using the webupd8 repository with the oracle-java8-installer, it's JAVA_HOME=/usr/lib/jvm/java-8-oracle.

Upvotes: 11

Uriah Carpenter
Uriah Carpenter

Reputation: 6726

The startup script at /etc/init.d/tomcat7 sources the file /etc/default/rcS before searching for some well-known install locations.

Adding the line JAVA_HOME=/usr/lib/jvm/java-8-oracle to /etc/default/rcS corrects the no JDK or JRE found startup problem without directly modifying the /etc/init.d/tomcat7 script.

Upvotes: 4

Kuba Rakoczy
Kuba Rakoczy

Reputation: 4124

You can set an environmental variable in the setenv.sh script. According to the Running The Apache Tomcat 7.0 document:

Apart from CATALINA_HOME and CATALINA_BASE, all environment variables can be specified in the "setenv" script. The script is placed either into CATALINA_BASE/bin or into CATALINA_HOME/bin directory and is named setenv.bat (on Windows) or setenv.sh (on *nix).

So just add the following line to setenv.sh:

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

This way you are setting the variable locally.

Upvotes: 2

Francesco Capodanno
Francesco Capodanno

Reputation: 186

Try install Java using the repository of http://www.webupd8.org .

This is for Java 8: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html

Upvotes: 0

chiastic-security
chiastic-security

Reputation: 20520

It'll need to be set for the user that runs the tomcat service, rather than for your user.

Set it in the system wide profile, somewhere in /etc/profile or /etc/profile.d/, depending on how your machine is configured.

Upvotes: 3

Related Questions