NoClassDefFoundError: Could not initialize class

NoClassDefFoundError: Could not initialize class

我正在使用 OpenSAML API 开发身份提供者。

我已经创建了一个 java 应用程序来测试 OpenSAML API,这是成功的。

现在的问题是我正在尝试使用 glassfish 在 Servlet 中使用那个 java 应用程序,但我现在正在失去理智。

听我说: 在开始使用 OpenSAML 之前,您必须调用它的 bootstrap 来启动它的组件,其中一个组件是 org.apache.xml.security.Init

所以我将 xmlsec.jar 添加到库中,但每次我 运行 WebApplication 它都会不断出现异常:

"java.lang.NoClassDefFoundError: Could not initialize class org.apache.xml.security.Init"

令人困惑的部分是,如果我从库中删除 xmlsec.jar,它仍然知道

import "org.apache.xml.security.Init" 

但是当我删除它并尝试重写它时:

import "org.apache.xml.security.Init"

现在它失败了,因为现在 org.apache 里面没有 xml.security。

有什么想法吗?

PS:我正在使用这些: -NetBeans IDE - 玻璃鱼 4.1.1 - Java EE 7 - JDK 1.8

glassfish 输出:

Warning:   StandardWrapperValve[LoginServlet]: Servlet.service() for servlet LoginServlet threw exception
java.lang.NoClassDefFoundError: Could not initialize class org.apache.xml.security.Init
at org.opensaml.DefaultBootstrap.initializeXMLSecurity(DefaultBootstrap.java:195)
at org.opensaml.DefaultBootstrap.bootstrap(DefaultBootstrap.java:98)
at opensamltest1.SAMLHelper.printSAMLObject(SAMLHelper.java:180)
at LoginServlet.processRequest(LoginServlet.java:53)
at LoginServlet.doPost(LoginServlet.java:100)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access0(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745)

原来你应该放弃 glassfish 去 JBoss。 那解决了我的问题。

谢谢。

这可能是由于 JVM 或容器主机提供的 classes 与 WAR 文件中的那些冲突。如果 class 在两个地方都重复,它会对您的启动造成各种破坏。