简体   繁体   中英

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.

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

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 .

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.

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.

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 .

我有同样的问题,但我通过更改/etc/init.d/tomcat JDK_DIR变量来解决它,如下所示:

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"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM