从apache官网下载64位tomcat7.0.90安装包文件解压到个人电脑D盘后,进入tomcat服务器的bin目录双击startup.bat windows批处理文件启动tomcat服务器时,出现闪退。
关于tomcat服务器启动出现闪退的问题,网上已有关于解决此类问题的描述,大部分都是因为未配置JAVA_HOME, JRE_HOME和CATALINA_HOME等环境变量而引起的。关于如何配置 3个环境变量,很多关于解决tomcat服务器启动闪退的博客甚至百度经验上都有,此处就不赘述了。不懂的同学可以参考这篇博客
如何解决tomcat启动闪退问题
但是也有特殊情况,就是你配置了上述环境变量后再此启动tomcat服务器还出现闪退的Bug, 这个时候我们就需要查看日志找到问题产生的原因。进入tomcat根目录的log文件夹如下图所示:
找到最近产生的catalina.+日期.txt文件,使用nodepad++打开查看内容,并把日志信息粘贴如下
九月 09, 2018 1:52:31 上午 org.apache.catalina.core.AprLifecycleListener init
警告: The APR based Apache Tomcat Native library failed to load. The error reported was [D:\tomcat7.0\apache-tomcat-7.0.90\bin\tcnative-1.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform]
java.lang.UnsatisfiedLinkError: D:\tomcat7.0\apache-tomcat-7.0.90\bin\tcnative-1.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.apache.tomcat.jni.Library.
at org.apache.tomcat.jni.Library.initialize(Library.java:178)
at org.apache.catalina.core.AprLifecycleListener.init(AprLifecycleListener.java:200)
at org.apache.catalina.core.AprLifecycleListener.isAprAvailable(AprLifecycleListener.java:108)
at org.apache.catalina.connector.Connector.setProtocol(Connector.java:592)
at org.apache.catalina.connector.Connector.
at org.apache.catalina.startup.ConnectorCreateRule.begin(ConnectorCreateRule.java:62)
at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1303)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1576)
at org.apache.catalina.startup.Catalina.load(Catalina.java:628)
at org.apache.catalina.startup.Catalina.load(Catalina.java:679)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:253)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:427)
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version: Apache Tomcat/7.0.90
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server built: Jul 2 2018 17:05:37 UTC
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Server number: 7.0.90.0
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name: Windows 10
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Version: 10.0
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Architecture: x86
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Java Home: C:\Program Files (x86)\Java\jre1.8.0_161
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Version: 1.8.0_161-b12
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Vendor: Oracle Corporation
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE: D:\tomcat7.0\apache-tomcat-7.0.90
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME: D:\tomcat7.0\apache-tomcat-7.0.90
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.util.logging.config.file=D:\tomcat7.0\apache-tomcat-7.0.90\conf\logging.properties
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dignore.endorsed.dirs=
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.base=D:\tomcat7.0\apache-tomcat-7.0.90
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.home=D:\tomcat7.0\apache-tomcat-7.0.90
九月 09, 2018 1:52:32 上午 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.io.tmpdir=D:\tomcat7.0\apache-tomcat-7.0.90\temp
九月 09, 2018 1:52:32 上午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8080"]
九月 09, 2018 1:52:32 上午 org.apache.coyote.AbstractProtocol init
严重: Failed to initialize end point associated with ProtocolHandler ["http-bio-8080"]
java.net.BindException: Address already in use: JVM_Bind
at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:413)
at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:728)
at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:452)
at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:119)
at org.apache.catalina.connector.Connector.initInternal(Connector.java:978)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:560)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:840)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
at org.apache.catalina.startup.Catalina.load(Catalina.java:654)
at org.apache.catalina.startup.Catalina.load(Catalina.java:679)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:253)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:427)
Caused by: java.net.BindException: Address already in use: JVM_Bind
at java.net.DualStackPlainSocketImpl.bind0(Native Method)
at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
at java.net.PlainSocketImpl.bind(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at java.net.ServerSocket.
at java.net.ServerSocket.
at org.apache.tomcat.util.net.DefaultServerSocketFactory.createSocket(DefaultServerSocketFactory.java:49)
at org.apache.tomcat.util.net.JIoEndpoint.bind(JIoEndpoint.java:400)
... 17 more
通过查看以上日志信息,我们发现这个bug主要由两处错误引起,第一处错误:
The APR based Apache Tomcat Native library failed to load. The error reported was [D:\tomcat7.0\apache-tomcat-7.0.90\bin\tcnative-1.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform]
java.lang.UnsatisfiedLinkError: D:\tomcat7.0\apache-tomcat-7.0.90\bin\tcnative-1.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform
原来是因为我的jdk平台是32位的,而tomcat7.0却是64位的,导致tomcat启动过程中加载native library失败。通过最开始的dos控制台信息我们发现tomcat启动时用到了jre,而我的环境变量配置的jre路径却是32位的(C:\Program Files (x86)目录下的安装软件都属于32bit位的软件)。原来的jdk和jre环境变量配置如下图所示
将jdk和jre的环境变量值加入到path值中,原来已配置好(如下图,本人采用的是win 10系统)
因此我的解决办法是安装64bit位的jdk,然后重新配置jdk和jre环境变量即可,配置后的jdk和jre环境变量如下图所示:
然后我们再来看第二处错误: java.net.BindException: Address already in use: JVM_Bind
这说明8080端口已被占用,这是由于我之前安装过32位的tomcat8.0并启动成功过导致的,这个问题我们可以通过tomcat\conf目录下的server.xml服务器的配置文件修改启动端口号来解决,tomcat服务器启动时默认的连接端口号是8080,现在我们把它改为8088就不会出现端口被占用的冲突了
redirectPort="8443" />
重启电脑后进入tomcat\bin目录,双击startup.bat文件不再出现闪退,并显示tomcat服务器启动成功,如下图所示。
进入浏览器输入http://localhost:8088并回车,进入如下界面说明tomcat服务器确实启动成功,问题到此得以解决