Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tomcat startup.sh trouble finding JAVA_HOME

Tags:

tomcat

I am a bit puzzled by this strange behavior on CentOs 5.4 when starting Tomcat 6.0 as a service

I've added a script at /etc/init.d/tomcat that can start/stop/restart Apache Tomcat 6.0 with user 'tomcat', and registered it as service. The problem with the service is that I am getting a 'Neither the JAVA_HOME nor the JRE_HOME environment variable is defined'. But when type 'sudo -u tomcat echo $JAVA_HOME' I get '/usr/java/jdk1.5.0_22' which is correct since I am using that JDK. What can I do about this?

like image 409
Petre Maierean Avatar asked Apr 02 '10 13:04

Petre Maierean


2 Answers

I had the same issue and solved it by placing the JAVA_HOME variable definition on file /etc/environment.

Initially I had created the JAVA_HOME environment variable invoking:

$ export JAVA_HOME=<path_to_my_java_home>

Then I realized Tomcat startup.sh script could not access the value of the JAVA_HOME variable when it was invoked with sudo, which is necessary to start Tomcat server.

First I tried exporting the JAVA_HOME variable with sudo, but it did not work:

$ sudo export JAVA_HOME=<path_to_my_java_home>
sudo: export: command not found

Then I tried adding the JAVA_HOME variable definition to /etc/environment file. Here is how my /etc/enviroment file looks like now:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
JAVA_HOME=/usr/lib/jvm/java-7-oracle

Then after invoking Tomcat startup.sh script with sudo and accessing http://localhost:8080 the brownser brings Tomcat startup page, which states the server is setup successfully.

like image 63
scodro Avatar answered Oct 25 '22 16:10

scodro


Have you tried forcing the JAVA_HOME env variable into the start script itself? Whenever I face a problem like this I find it a good troubleshooting technique to try and track down where it is losing this info by setting it in the scripts themselves.

like image 30
Gray Area Avatar answered Oct 25 '22 16:10

Gray Area