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.

share|improve this question
    
First: You export the environment variables as "omkars" and start "tomcat7" as root using sudo; the environments won't be passed to that process. Second: I don't have Ubuntu at hand but: on RedHat/CentOS there are application server configs under /etc/ specifying environments to use for startup. Try to grep /etc for "JAVA_HOME". – try-catch-finally Dec 13 '14 at 9:40
up vote 22 down vote accepted

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

share|improve this answer
    
You should accept this as the correct answer. The problem is because the Ubuntu init.d startup script (if installed via apt-get) for Tomcat does not check for a java 8 jdk. – Chris Clark Feb 1 '15 at 19:06
    
Thanks @ChrisClark. – Omkar Feb 2 '15 at 4:53
    
Thanks @Omkar your answer is very helpful. – pedro.olimpio Dec 10 '15 at 21:02
    
This answer appears very useful. I need to edit the file of concern inside a Vagrant provisioned virtual machine. The given line does not exist anymore. – Nikos Alexandris Dec 26 '15 at 21:47

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.