either the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
在执行jenkins 通过ssh远程操作重启tomcat时,出现了以上错误。明显是环境变量问题,但是服务环境变量是无误的。
有两种解决方案,
1.如果是在 /etc/profile 中导入的环境变量,那么在/root/.bashrc中加入相同环境变量
export JAVA_HOME=/home/jdk1.8.0_181
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
并执行 source /root/.bashrc
2.直接在重启脚本中加入
#!/bin/sh
export JAVA_HOME=/home/jdk1.8.0_181
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
TOMCAT_PATH=$1bin
echo "TOMCAT_PATH is $TOMCAT_PATH"
PID=`ps aux | grep $1 | grep java | awk '{print $2}'`
if [ -n "$PID" ]; then
echo "Will shutdown tomcat: $PID"
$TOMCAT_PATH/shutdown.sh -force
sleep 5
else echo "No Tomcat Process $PID"
fi
sleep 1
$TOMCAT_PATH/startup.sh