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?
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.
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.
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