Tomcat

Tomcat 啟動 - 錯誤:無法找到或載入主類

  • February 9, 2018

當我嘗試在 RHEL6/Java7 上啟動 Tomcat (7.0.82) 時,日誌將顯示如下:

Error: Could not find or load main class

請注意,在日誌條目的末尾沒有指定特定的類。Google上的大多數點擊似乎都在日誌條目的末尾指示了一個特定的類。

就我而言,我將這兩個伺服器配置相同(AFAIK)。但是,一台伺服器不想啟動。伺服器是使用下載的二進製文件、自定義初始化腳本等安裝的;到目前為止,使用的 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.sh和的輸出configtest.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

setenv.sh有編碼問題和不正確的 EOL。一旦這些被修復,事情就會像預期的那樣啟動和執行。

此問題與您的setenv.sh直接相關,並且如上所述,是由於編碼和格式不正確造成的。就我而言,有兩個錯誤:

  1. VMargs 中的額外空格。例子:

Dcatalina.base= /some/locationDcatalina.base =/some/locationDcatalina.base = /some/location

由於“=”周圍的空格而出錯。

  1. 第二個問題與行尾有關。確保如果您使用 unix/linux,您的 setenv.sh 必須以 unix 樣式的行結尾保存。(可以在保存時在 Notepad++ 或 gedit 中完成)。而如果您使用的是 Windows,則您的 setenv.bat 必須具有 Windows 樣式的行尾。

檢查這一點的一種方法是嘗試通過執行 setenv.sh 來執行./setenv.sh。如果它沒有顯示任何輸出,則您的格式很好

引用自:https://serverfault.com/questions/885854