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.
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.
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.
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.
Now, its working!
Changes I have done are:
.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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With