在用命令
./startup.sh
启动tomcat时报错:
Cannot find /usr/local/tomcat/bin/setclasspath.sh
This file is needed to run this program
在tomcat的bin目录下我们看下catalina.sh文件:
vi catalina.sh
搜索下setclasspath:
?setclasspath
然后我们定位到搜索的地方:
if $os400; then
# -r will Only work on the os400 if the files are:
# 1. owned by the user
# 2. owned by the PRIMARY group of the user
# this will not work if the user belongs in secondary groups
. "$CATALINA_HOME"/bin/setclasspath.sh
else
if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then
. "$CATALINA_HOME"/bin/setclasspath.sh
else
echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh"
echo "This file is needed to run this program"
exit 1
fi
fi
报这个错是因为$CATALINA_HOME配置的有问题导致无法找到/bin/setclasspath.sh导致的。
1.因为$CATALINA_HOME是配置在/etc/profile中的,所以我们修改下/etc/profile:
vi /etc/profile
2.修改tomcat的配置信息TOMCAT_HOME和CATALINA_HOME为自己的tomcat文件位置,我的是下面这样:
export TOMCAT_HOME=/usr/local/tomcat/apache-tomcat-9.0.40
export CATALINA_HOME=/usr/local/tomcat/apache-tomcat-9.0.40
3.设置环境变量立即生效:
source /etc/profile
4.最后再启动tomcat就好啦
5.如果你的tomcat是使用 docker 安装启动报这个错的话:
docker中此报错的其他解决办法你可以参考其他文章:
Latest image incompatible with old versions of docker engine
Tomcat 9 running on docker - Cannot find /usr/local/tomcat/bin/setclasspath.sh
Tomcat 9 running on docker - Cannot find /usr/local/tomcat/bin/setclasspath.sh