Classloading problem "NoClassDefFoundError: net/sf/ehcache/Ehcache" when using CXF library with Ehcache

Solution Unverified - Updated -

Issue

  • ClassNotfoundException (CNF) when depending on JBoss CXF Module and packaging Ehcache library in WEB-INF/lib where Spring is also used.
  • In the initial configuration of our Web Application we use ehcache.2.7.0.jar in WEB-INF/lib (we use Spring and ehcache for same utilities). Using CXF for Web Services calls, at runtime we have the following exception:
java.lang.NoClassDefFoundError: net/sf/ehcache/Ehcache

Full stacktrace

java.lang.NoClassDefFoundError: net/sf/ehcache/Ehcache
    at org.apache.cxf.ws.security.tokenstore.EHCacheTokenStoreFactory.newTokenStore(EHCacheTokenStoreFactory.java:34)
    at org.apache.cxf.ws.security.policy.interceptors.IssuedTokenInterceptorProvider.createTokenStore(IssuedTokenInterceptorProvider.java:107)
    at org.apache.cxf.ws.security.policy.interceptors.IssuedTokenInterceptorProvider.getTokenStore(IssuedTokenInterceptorProvider.java:116)
    at org.apache.cxf.ws.security.policy.interceptors.IssuedTokenInterceptorProvider$IssuedTokenOutInterceptor.handleDelegation(IssuedTokenInterceptorProvider.java:232)
    at org.apache.cxf.ws.security.policy.interceptors.IssuedTokenInterceptorProvider$IssuedTokenOutInterceptor.issueToken(IssuedTokenInterceptorProvider.java:448)
    at org.apache.cxf.ws.security.policy.interceptors.IssuedTokenInterceptorProvider$IssuedTokenOutInterceptor.handleMessage(IssuedTokenInterceptorProvider.java:149)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
    at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:530)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
    at $Proxy48.zCDAGCOOPITCUSTGETLIST(Unknown Source)
    at com.test.application.SAML2StateLess.methodA(SAML2StateLess.java:126)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
.. .. ..
Caused by: java.lang.ClassNotFoundException: net.sf.ehcache.Ehcache from [Module "org.apache.cxf.impl:main" from local module loader @51ab8a5 (finder: local module finder @1d505b41 (roots: /opt/jboss-eap-6.1/modules,/opt/jboss-eap-6.1/modules/system/layers/base))]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
    ... 93 more

Environment

Red Hat JBoss Enterprise Application Platform (EAP) 6.1.0

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content