Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 706
Omkar Shetkar Avatar asked Dec 13 '14 09:12

Omkar Shetkar


People also ask

How do I start tomcat7 in Ubuntu?

Type in sudo service tomcat7 start and then hit Enter : You will receive the following message indicating the server is started: To stop the Tomcat server, type in sudo service tomcat7 start and then hit Enter in the original terminal window: You will receive a message indicating the Tomcat server has been stopped.

Where is JAVA_HOME in Ubuntu?

From the java installation that you use select the path up to jre . e.g. /usr/lib/jvm/java-8-oracle/ . This will become your JAVA_HOME path.

Does Tomcat use JAVA_HOME?

To understand how Tomcat pick up which JDK to run, refer to the Tomcat startup script – /etc/init. d/tomcat7 . Normally, Tomcat will use the JDK which configured in the JAVA_HOME environment, if JAVA_HOME is not set, Tomcat will find a random JDK from a pre-defined location.


6 Answers

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

like image 184
Omkar Shetkar Avatar answered Oct 13 '22 21:10

Omkar Shetkar


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.

like image 21
Buzz Killington Avatar answered Oct 13 '22 21:10

Buzz Killington


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.

like image 38
chiastic-security Avatar answered Oct 13 '22 20:10

chiastic-security


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.

like image 45
Uriah Carpenter Avatar answered Oct 13 '22 20:10

Uriah Carpenter


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.

like image 30
Kuba Rakoczy Avatar answered Oct 13 '22 21:10

Kuba Rakoczy


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"
like image 30
sentechno Avatar answered Oct 13 '22 22:10

sentechno