tomcat启动报错Cannot find /usr/local/tomcat/bin/setclasspath.sh原因

在用命令

./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 安装启动报这个错的话:

  • 请使用 tomcat:9-jdk8-temurin-focal 这个镜像来解决报错,或者使用如下命令来拉取镜像:
 docker pull tomcat:9.0.56-jdk8-temurin-focal

然后使用镜像id来启动。


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

你可能感兴趣的:(其他,linux,tomcat,java,centos)