Set the JDK environment variable, and the command line uses java-version
Use the service tomcat-web1 Start command to report the following error
Neither the Java_home nor the JRE_HOME environment variable is defined. At least one of these environment variable are needed to run this program
Note: TOMCAT-WEB1 is the Tomcat service name, Tomcat set up the service method online there are many no longer repeat
One way is to modify the setclasspath.sh, adding at the beginning of the SH script
java_home=/usr/lib/java-1.7.0
But this method is not good, if the Java home changes also need to modify the shell
So in a different way, look at the shell script first.
catalina_home_data=/usr/local/tomcat/tomcat7.< Span class= "Hljs-number" >0 start_tomcat= $CATALINA _home_data /bin/ Startup.shstop_tomcat= $CATALINA _home_data /bin/shutdown.sh start () {${start_tomcat} if [$? -eq 0 ]; then printf "Tomcat7-data started \t\t\t\t\t[\033[32m ok \033[m]\n" ; else printf "Tomcat7-data started \t\t\t\t\t[\033[31m FAIL \033[m]\n" ; fi }
The
service runs the specified services (known as the System V initial script), removing most of the environment variables, preserving only the Lang and term environment variables, and setting the current path to/, that is, running the service script in a very clean environment that can be predicted.
The environment variable cannot be found while the script is running, so modify it to the following script
catalina_home_data=/usr/local/tomcat/tomcat7. 0 start_tomcat= $CATALINA _home_data /bin/ Startup.shstop_tomcat= $CATALINA _home_data /bin/shutdown.sh start () {su-root-c "${start_tomcat} " if [$?] -eq 0 ]; then printf "Tomcat7-data started \t\t\t\t\t[\033[32m ok \033[m]\n" ; else printf "Tomcat7-data started \t\t\t\t\t[\033[31m FAIL \033[m]\n" ; fi }
Su-root-c "${start_tomcat}"
-Represents the execution environment variable
-C is the Execute command
The overall command means to execute the/usr/local/tomcat/tomcat7.0/bin/startup.sh command in the same way as the root user and with environment variables
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The issue of switching openjdk to Oracle JDK in CentOS will cause Tomcat to not start properly