Tomcat 启动-错误:无法找到或加载主类

Tomcat 启动-错误:无法找到或加载主类

当我尝试在 RHEL6/Java7 上启动 Tomcat (7.0.82) 时,日志将显示以下内容:

Error: Could not find or load main class

注意,日志条目末尾没有指定具体类别。Google 上的大多数搜索结果似乎都表明日志条目末尾有一个具体类别。

就我而言,我对这两台服务器进行了相同的配置(据我所知)。但是,一台服务器无法启动。该服务器是使用下载的二进制文件、自定义初始化脚本等安装的;使用一个 Ansible 脚本,到目前为止,该脚本在总共 3 台服务器上运行(所有服务器都使用相同的操作系统,Java)。

发出命令:service tomcat start

服务器 A-工作正常

Using CATALINA_BASE:   /opt/tomcat/current
Using CATALINA_HOME:   /opt/tomcat/current
Using CATALINA_TMPDIR: /opt/tomcat/current/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/current/bin/bootstrap.jar:/opt/tomcat/current/bin/tomcat-juli.jar
Tomcat started.

服务器 B – 没有(尽管指示“已启动”)

Using CATALINA_BASE:   /opt/tomcat/current
Using CATALINA_HOME:   /opt/tomcat/current
Using CATALINA_TMPDIR: /opt/tomcat/current/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/current/bin/bootstrap.jar:/opt/tomcat/current/bin/tomcat-juli.jar
Tomcat started.

更新 #1

输出catalina.out

[me@server tomcat]$ cat /var/log/tomcat/catalina.out
Error: Could not find or load main class

更新 #2

输出version.shconfigtest.sh

version.sh

[me@server bin]$ ./version.sh
Using CATALINA_BASE:   /opt/tomcat/apache-tomcat-7.0.82
Using CATALINA_HOME:   /opt/tomcat/apache-tomcat-7.0.82
Using CATALINA_TMPDIR: /opt/tomcat/apache-tomcat-7.0.82/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/apache-tomcat-7.0.82/bin/bootstrap.jar:/opt/tomcat/apache-tomcat-7.0.82/bin/tomcat-juli.jar
Server version: Apache Tomcat/7.0.82
Server built:   Sep 29 2017 12:23:15 UTC
Server number:  7.0.82.0
OS Name:        Linux
OS Version:     2.6.32-696.13.2.el6.x86_64
Architecture:   amd64
JVM Version:    1.7.0_45-b18
JVM Vendor:     Oracle Corporation

configtest.sh

[me@server bin]$ ./configtest.sh
Using CATALINA_BASE:   /opt/tomcat/apache-tomcat-7.0.82
Using CATALINA_HOME:   /opt/tomcat/apache-tomcat-7.0.82
Using CATALINA_TMPDIR: /opt/tomcat/apache-tomcat-7.0.82/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat/apache-tomcat-7.0.82/bin/bootstrap.jar:/opt/tomcat/apache-tomcat-7.0.82/bin/tomcat-juli.jar
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/7.0.82
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Sep 29 2017 12:23:15 UTC
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         7.0.82.0
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Linux
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            2.6.32-696.13.2.el6.x86_64
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             /usr/java/jre1.7.0_45
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.7.0_45-b18
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         /opt/tomcat/apache-tomcat-7.0.82
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         /opt/tomcat/apache-tomcat-7.0.82
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/opt/tomcat/apache-tomcat-7.0.82/endorsed
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/opt/tomcat/apache-tomcat-7.0.82
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/opt/tomcat/apache-tomcat-7.0.82
Nov 30, 2017 10:13:59 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.io.tmpdir=/opt/tomcat/apache-tomcat-7.0.82/temp
Nov 30, 2017 10:13:59 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Nov 30, 2017 10:14:00 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Nov 30, 2017 10:14:00 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Nov 30, 2017 10:14:00 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1881 ms

答案1

setenv.sh存在编码问题和不适当的 EOL。修复这些问题后,一切便可按预期正常运行。

答案2

此问题与您的设置环境变量如上所述,这是由于不正确的编码和格式问题造成的。就我而言,有两个错误:

  1. VMargs 中有多余的空格。例如:

Dcatalina.base= /some/location或者Dcatalina.base =/some/location 或者Dcatalina.base = /some/location

由于“=”周围有空格,所以是错误的。

  1. 第二个问题与行尾有关。如果您使用的是 unix/linux,请确保您的 setenv.sh 必须使用 unix 样式的行尾保存。(可以在保存时在 Notepad++ 或 gedit 中完成)。而如果您使用的是 Windows,您的 setenv.bat 必须具有 windows 样式的行尾。

检查这一点的一种方法是尝试通过执行以下操作来运行 setenv.sh ./setenv.sh。如果它才不是显示任何输出,您的格式是美好的

相关内容