Search code examples
javaservletsglassfishnoclassdeffounderroropensaml

NoClassDefFoundError: Could not initialize class


I'm developing an Identity Provider using OpenSAML API.

I have created a java application to test OpenSAML API which was a success.

The problem is now I'm trying to use that java Application in Servlet using glassfish and I'm loosing my mind right now.

Hear me out: before you can start using OpenSAML you have to call it's bootstrap to initiate it's components, one of those components is org.apache.xml.security.Init

so i added xmlsec.jar into libraries but every time I run the WebApplication it keeps on getting an exception:

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

the confusing part is if I remove the xmlsec.jar from libs, it still knows the

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

but when I delete that and try to rewrite the same:

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

now it fails because now org.apache doesn't have xml.security in it.

any idea guys?

PS: I'm using these: - NetBeans IDE - Glassfish 4.1.1 - Java EE 7 - JDK 1.8

glassfish output:

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$9.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.access$100(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)

Solution

  • Turns out you should abandon glassfish and go to JBoss. That solved my problem.

    Thanks.