解决IDEA配置tomcat启动报错问题
这篇文章主要介绍了解决IDEA配置tomcat启动报错问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
在配置servlet不同路径时遇上以下两个错误:
java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;java.lang.ClassNotFoundException: org.apache.jsp.index_jsp;
对于第一个问题,我上网查阅了很多资料后发现,可能是tomcat版本冲突导致,catalina log如下:
19-Feb-2018 08:26:44.175 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.2819-Feb-2018 08:26:44.175 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Feb 6 2018 23:10:25 UTC19-Feb-2018 08:26:44.175 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.28.019-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Windows 719-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 6.119-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: x8619-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: C:\Program Files\Java\jdk1.8.0_141\jre19-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_141-b1519-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation19-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: F:\apache-tomcat-8.5.2819-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: F:\apache-tomcat-8.5.2819-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=F:\apache-tomcat-8.5.28\conf\logging.properties19-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager19-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=204819-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources19-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=19-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=F:\apache-tomcat-8.5.2819-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=F:\apache-tomcat-8.5.2819-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=F:\apache-tomcat-8.5.28\temp19-Feb-2018 08:26:44.191 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.16] using APR version [1.6.3].19-Feb-2018 08:26:44.206 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].19-Feb-2018 08:26:44.206 信息 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]19-Feb-2018 08:26:44.830 信息 [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2m 2 Nov 2017]19-Feb-2018 08:26:45.080 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]19-Feb-2018 08:26:45.517 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read19-Feb-2018 08:26:45.581 信息 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]19-Feb-2018 08:26:45.597 信息 [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read19-Feb-2018 08:26:45.597 信息 [main] org.apache.catalina.startup.Catalina.load Initialization processed in 2422 ms19-Feb-2018 08:26:45.643 信息 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]19-Feb-2018 08:26:45.643 信息 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.2819-Feb-2018 08:26:45.675 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [F:\apache-tomcat-8.5.28\webapps\docs]19-Feb-2018 08:26:46.423 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [F:\apache-tomcat-8.5.28\webapps\docs] has finished in [748] ms19-Feb-2018 08:26:46.423 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [F:\apache-tomcat-8.5.28\webapps\examples]19-Feb-2018 08:26:47.059 严重 [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/examples]]at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1141)at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)at java.util.concurrent.FutureTask.run(FutureTask.java:266)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)Caused by: org.apache.catalina.LifecycleException: Failed to start component [Pipeline[StandardEngine[Catalina].StandardHost[localhost].StandardContext[/examples]]]at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5125)at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)... 10 moreCaused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.authenticator.FormAuthenticator[/examples]]at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:182)at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)... 12 moreCaused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;at org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1186)at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)... 14 more
19-Feb-2018 08:26:47.075 严重 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Error deploying web application directory [F:\apache-tomcat-8.5.28\webapps\examples]java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/examples]]at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:756)at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1141)at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)at java.util.concurrent.FutureTask.run(FutureTask.java:266)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at java.lang.Thread.run(Thread.java:748)
我先试着删除其他Tomcat版本,重新配置tomcat环境变量并重新部署Tomcat。发现并没有解决问题,再次上网查阅,发现getContextPath()在servlet2.5特有。于是试着删除原先jar包中的servlet-api.jar,然后重新部署项目。发现了第二个问题,log如下:
19-Feb-2018 09:59:51.534 严重 [http-nio-8080-exec-3] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [jsp] in context with path [/Happy] threw exception [java.lang.ClassNotFoundException: org.apache.jsp.index_jsp] with root causejava.lang.ClassNotFoundException: org.apache.jsp.index_jspat java.net.URLClassLoader.findClass(URLClassLoader.java:381)at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:129)at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:60)at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:159)at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:171)at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:380)at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)at java.lang.Thread.run(Thread.java:748)
19-Feb-2018 10:03:45.289 严重 [http-nio-8080-exec-1] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [jsp] in context with path [/Happy] threw exception [Unable to compile class for JSP] with root causejava.lang.ClassNotFoundException: com.sun.el.ExpressionFactoryImplat org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)at javax.el.FactoryFinder.newInstance(FactoryFinder.java:83)at javax.el.FactoryFinder.find(FactoryFinder.java:193)at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:185)at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:156)at org.apache.jasper.compiler.PageInfo.<init>(PageInfo.java:80)at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:117)at org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)at org.apache.jasper.compiler.Compiler.compile(Compiler.java:351)at org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:595)at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:368)at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)at java.lang.Thread.run(Thread.java:748)
再次查阅资料,发现是缺少jar包。因为jdk1.8的扩展jar包里没有servlet相关api,故IDEA会导入失败。
参考:http://www.cncsto.com/article/1005
此时需要导入jar包,之前我是下载相关api
然后放到下图目录中
为了防止出现缺少jar包问题,建议直接去tomcat目录下的lib中找到servlet-api.jar,直接复制到ext中。然后再重新部署一下tomcat,问题解决。
总结
到此这篇关于解决IDEA配置tomcat启动报错问题的文章就介绍到这了