Reputation: 914
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?
Upvotes: 6
Views: 27163
Reputation: 449
In bin/catalina.sh just add JAVA_HOME for crontab as
# For CRONTAB
export JAVA_HOME=/usr/java/latest
# END
Upvotes: 0
Reputation: 345
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.
Upvotes: 3
Reputation: 121
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.
Upvotes: 12
Reputation: 6302
Have you checked the paths in /etc/profile.d/java.sh ?
Also try checking which java version it return with: which java
this should return the exact paths in java.sh if not you have a misconfiguration. in the later case uninstall all java and reinstall latest jdk.
Anyhow this posts comes in handy in your favorites for later reference.
http://www.centos.org/modules/newbb/viewtopic.php?topic_id=5717&forum=28
Upvotes: 0