Tomcat war run application - 无法启动组件

须知少年凌云志,曾许人间第一流。这篇文章主要讲述Tomcat war run application - 无法启动组件相关的知识,希望能为你提供帮助。
我尝试运行WAR到我的Tomcat 9.0.5部署正常,但当我尝试启动应用程序时,我得到了这个例外:

28-Feb-2018 10:17:33.328 SEVERE [http-nio-8080-exec-8] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/AppName]] 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.deployWAR(HostConfig.java:986) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:507) at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1651) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1517) at org.apache.catalina.manager.htmlManagerServlet.upload(HTMLManagerServlet.java:285) at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:206) at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:136) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 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.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108) 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.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:613) at org.apache.catalina.valves.RequestFilterValve.process(RequestFilterValve.java:348) at org.apache.catalina.valves.RemoteAddrValve.invoke(RemoteAddrValve.java:52) 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) Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ws/rs/core/Application at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2283) at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:811) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1260) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:188) at org.apache.catalina.startup.WebappServiceLoader.load(WebappServiceLoader.java:159) at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1621) at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1134) at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:774) at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:299) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5113) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 48 more

当我尝试在Weblogic 12.c上运行时没有任何问题。
这就是我的pom.xml的样子:
< project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> < modelVersion> 4.0.0< /modelVersion> < groupId> com.app< /groupId> < artifactId> AppName< /artifactId> < packaging> war< /packaging> < version> 0.0.1-SNAPSHOT< /version> < name> AppName Maven Webapp< /name> < url> http://maven.apache.org< /url> < dependencies> < dependency> < groupId> junit< /groupId> < artifactId> junit< /artifactId> < version> 3.8.1< /version> < scope> test< /scope> < /dependency> < dependency> < groupId> javax< /groupId> < artifactId> javaee-api< /artifactId> < version> 6.0< /version> < scope> provided< /scope> < /dependency> < !-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> < dependency> < groupId> org.projectlombok< /groupId> < artifactId> lombok< /artifactId> < version> 1.16.6< /version> < scope> provided< /scope> < /dependency> < !-- https://mvnrepository.com/artifact/org.primefaces/primefaces --> < dependency> < groupId> org.primefaces< /groupId> < artifactId> primefaces< /artifactId> < version> 6.0< /version> < /dependency> < !-- https://mvnrepository.com/artifact/log4j/log4j --> < dependency> < groupId> log4j< /groupId> < artifactId> log4j< /artifactId> < version> 1.2.17< /version> < /dependency> < dependency> < groupId> asm< /groupId> < artifactId> asm< /artifactId> < version> 3.3.1< /version> < /dependency> < dependency> < groupId> com.sun.jersey< /groupId> < artifactId> jersey-bundle< /artifactId> < version> 1.19.4< /version> < /dependency> < dependency> < groupId> org.json< /groupId> < artifactId> json< /artifactId> < version> 20170516< /version> < /dependency> < dependency> < groupId> com.sun.jersey< /groupId> < artifactId> jersey-server< /artifactId> < version> 1.19.4< /version> < /dependency> < dependency> < groupId> com.sun.jersey< /groupId> < artifactId> jersey-core< /artifactId> < version> 1.19.4< /version> < /dependency> < dependency> < groupId> javax< /groupId> < artifactId> javaee-api< /artifactId> < version> 6.0< /version> < /dependency> < !-- https://mvnrepository.com/artifact/org.chartistjsf/ChartistJSF --> < dependency> < groupId> org.chartistjsf< /groupId> < artifactId> ChartistJSF< /artifactId> < version> 3.0< /version> < /dependency> < !-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload --> < dependency> < groupId> commons-fileupload< /groupId> < artifactId> commons-fileupload< /artifactId> < version> 1.2< /version> < /dependency> < /dependencies> < build> < finalName> AppName< /finalName> < plugins> < plugin> < artifactId> maven-compiler-plugin< /artifactId> < configuration> < source> 1.8< /source> < target> 1.8< /target> < skip> true< /skip> < /configuration> < /plugin> < plugin> < groupId> org.apache.maven.plugins< /groupId> < artifactId> maven-war-plugin< /artifactId> < configuration> < webXml> WebContentWEB-INFweb.xml< /webXml> < /configuration> < /plugin> < /plugins> < /build> < /project>

问题是什么?我该怎么办?谢谢!
答案Weblogic是一个完整的Java EE服务器,而Tomcat只是一个servlet容器。您使用的是Jersey,它是JAX-RS的一种实现,默认情况下在Tomcat中不可用。这意味着当您尝试在Tomcat中加载JAX-RS类时,它将无法找到它们。要解决此问题,您还需要添加JAX-RS api作为依赖项(非提供)。
将其添加到您的pom中:
< dependency> < groupId> javax.ws.rs< /a> < /groupId> < artifactId> javax.ws.rs< /a> -api< /artifactId> < version> 2.0.1< /version> < /dependency>

此外,Jersey工件的位置已被移动,以使用最新版本:
< dependency> < groupId> org.glassfish.jersey.containers< /groupId> < artifactId> jersey-container-servlet< /artifactId> < version> 2.22.1< /version> < /dependency> < !-- Required only when you are using JAX-RS Client --> < dependency> < groupId> org.glassfish.jersey.core< /groupId> < artifactId> jersey-client< /artifactId> < version> 2.22.1< /version> < /dependency>

另一答案您应该只将javaee-api作为提供的依赖项,删除这些行:
< dependency> < groupId> javax< /groupId> < artifactId> javaee-api< /artifactId> < version> 6.0< /version> < /dependency>

另一答案我建议你从http://java.sun.com/javaee/获取完整版的javaee.jar文件。 javaee.jar一般位于“ JAVA_HOMElib”文件夹中。将此jar包含在Maven资源库/类路径中。这应该可以解决您的问题。完成此操作后,从pom.xml中删除依赖项。
另一答案试着改变
< dependency> < groupId> javax< /groupId> < artifactId> javaee-api< /artifactId> < version> 6.0< /version> < scope> provided< /scope> < /dependency>


< !-- https://mvnrepository.com/artifact/org.jboss.spec/jboss-javaee-7.0 --> < dependency> < groupId> org.jboss.spec< /groupId> < artifactId> jboss-javaee-7.0< /artifactId> < version> 1.0.3.Final< /version> < type> pom< /type> < scope> provided< /scope> < /dependency>

另一答案java.net中的javaee不包含任何方法体,但仅包含API名称。因此,它只能用于编译,而不能用于与应用程序一起运行或部署
【Tomcat war run application - 无法启动组件】您的应用程序能够在Weblogic中运行的原因是,Weblogic与Java EE兼容。如果您需要在tomcat中运行,请从http://java.sun.com/javaee/获取原始完整版本的javaee.jar文件。
只需下载并安装J2EE SDK,就可以在“ J2EE_SDK_FOLDERlib”文件夹中找到javaee.jar。将它包含到您的本地Maven存储库或poject类路径将摆脱上述错误消息

    推荐阅读