java.lang.NoClassDefFoundError 在 GlassFish/Payara 上部署 war 时

java.lang.NoClassDefFoundError when deploying war on GlassFish/Payara

Info:   WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
            WARN:   WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.servlet.internal.CdiExternalRequestScope is deprecated from CDI 1.1!
            WARN:   WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.WebAppExceptionHolder is deprecated from CDI 1.1!
            WARN:   WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.WebAppExceptionInterceptor is deprecated from CDI 1.1!
            WARN:   WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.TransactionalExceptionMapper is deprecated from CDI 1.1!
            WARN:   WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider$JaxRsParamProducer is deprecated from CDI 1.1!
            Severe:   Error invoking ServletContainerInitializer org.jboss.weld.environment.servlet.EnhancedListener
            java.lang.NoClassDefFoundError: org/apache/tomcat/InstanceManager
                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.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:1093)
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1624)
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1505)
                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.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:1093)
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1624)
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1505)
                at org.jboss.weld.environment.tomcat.TomcatContainer.initialize(TomcatContainer.java:43)
                at org.jboss.weld.environment.servlet.WeldServletLifecycle.initialize(WeldServletLifecycle.java:213)
                at org.jboss.weld.environment.servlet.EnhancedListener.onStartup(EnhancedListener.java:62)
                at org.apache.catalina.core.StandardContext.callServletContainerInitializers(StandardContext.java:5825)
                at com.sun.enterprise.web.WebModule.callServletContainerInitializers(WebModule.java:737)
                at org.apache.catalina.core.StandardContext.start(StandardContext.java:5722)
                at com.sun.enterprise.web.WebModule.start(WebModule.java:618)
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:956)
                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:939)
                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:684)
                at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2105)
                at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1750)
                at com.sun.enterprise.web.WebApplication.start(WebApplication.java:107)
                at org.glassfish.internal.data.EngineRef.start(EngineRef.java:123)
                at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:294)
                at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:357)
                at com.sun.enterprise.v3.server.ApplicationLifecycle.initialize(ApplicationLifecycle.java:541)
                at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:542)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.run(CommandRunnerImpl.java:549)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.run(CommandRunnerImpl.java:545)
                at java.security.AccessController.doPrivileged(Native Method)
                at javax.security.auth.Subject.doAs(Subject.java:360)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.execute(CommandRunnerImpl.java:544)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.run(CommandRunnerImpl.java:575)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.run(CommandRunnerImpl.java:567)
                at java.security.AccessController.doPrivileged(Native Method)
                at javax.security.auth.Subject.doAs(Subject.java:360)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:566)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1475)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.access00(CommandRunnerImpl.java:111)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1857)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1733)
                at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:564)
                at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:251)
                at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:166)
                at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:516)
                at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:213)
                at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
                at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
                at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
                at org.glassfish.grizzly.filterchain.ExecutorResolver.execute(ExecutorResolver.java:95)
                at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
                at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
                at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
                at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
                at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
                at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
                at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
                at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
                at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access0(WorkerThreadIOStrategy.java:33)
                at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
                at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
                at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
                at java.lang.Thread.run(Thread.java:748)
            Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.InstanceManager
    I'm
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1659)
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1505)
                ... 66 more

            Severe:   Startup of context /nrd failed due to previous errors
            Severe:   Exception during cleanup after start failed

我正在尝试在 payara5/glassfish 网络服务器上部署 war。带有 tomcat 的应用程序 运行 但是当我尝试部署 war 文件时它会抛出上述错误。 Clean Build 项目没有帮助。当我在 Glassfish 上部署它时,为什么我应该在项目中包含一个包含 Tomcat 实例管理器 class 的 jar?我应该在项目中包含哪个 jar?谢谢

好吧,从 StackTrace 来看,您正在将 Weld 与 Tomcat 结合使用。在 Tomcat 中使用 Weld 需要配置才能集成 Weld 和 Tomcat。但是,切换到 GlassFish/Payara 时不再需要此类集成,因为它们已经支持开箱即用的 Weld。

所以,我认为您必须先删除所有关于集成 Tomcat 和 Weld 的配置。我建议您确保首先删除所有提到的配置 here