Wildfly Server, Maven, RestEasy (java.lang.ClassNotFoundException: org.jboss.resteasy.core.ResourceMethod)

Stefan Zahariev picture Stefan Zahariev · Jul 13, 2016 · Viewed 10.8k times · Source

I migrate a project from JBOSS to Wildfly Server. I made some changes in standalone.xml and everything works fine, BUT when I send a JSON request from Postman I get the following exception:

ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /service/api/authenticate: java.lang.NoClassDefFoundError: org/jboss/resteasy/core/ResourceMethod
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethods(Class.java:1975)
    at org.jboss.resteasy.core.PropertyInjectorImpl.populateMap(PropertyInjectorImpl.java:73)
    at org.jboss.resteasy.core.PropertyInjectorImpl.<init>(PropertyInjectorImpl.java:54)
    at org.jboss.resteasy.core.InjectorFactoryImpl.createPropertyInjector(InjectorFactoryImpl.java:65)
    at org.jboss.resteasy.cdi.CdiInjectorFactory.createPropertyInjector(CdiInjectorFactory.java:113)
    at org.jboss.resteasy.spi.ResteasyProviderFactory.injectedInstance(ResteasyProviderFactory.java:2237)
    at org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry$AbstractInterceptorFactory.createInterceptor(JaxrsInterceptorRegistry.java:170)
    at org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry$LegacyPerMethodInterceptorFactory.getInterceptor(JaxrsInterceptorRegistry.java:329)
    at org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry$AbstractLegacyInterceptorFactory.getLegacyMatch(JaxrsInterceptorRegistry.java:269)
    at org.jboss.resteasy.core.interception.ContainerRequestFilterRegistry$1.postMatch(ContainerRequestFilterRegistry.java:67)
    at org.jboss.resteasy.core.interception.JaxrsInterceptorRegistry.postMatch(JaxrsInterceptorRegistry.java:405)
    at org.jboss.resteasy.core.interception.ContainerRequestFilterRegistry.postMatch(ContainerRequestFilterRegistry.java:57)
    at org.jboss.resteasy.core.ResourceMethodInvoker.<init>(ResourceMethodInvoker.java:105)
    at org.jboss.resteasy.core.ResourceMethodRegistry.processMethod(ResourceMethodRegistry.java:281)
    at org.jboss.resteasy.core.ResourceMethodRegistry.register(ResourceMethodRegistry.java:252)
    at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:222)
    at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:194)
    at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:180)
    at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:157)
    at org.jboss.resteasy.core.ResourceMethodRegistry.addPerRequestResource(ResourceMethodRegistry.java:76)
    at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:404)
    at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:245)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:113)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36)
    at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:117)
    at org.wildfly.extension.undertow.security.RunAsLifecycleInterceptor.init(RunAsLifecycleInterceptor.java:78)
    at io.undertow.servlet.core.LifecyleInterceptorInvocation.proceed(LifecyleInterceptorInvocation.java:103)
    at io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:231)
    at io.undertow.servlet.core.ManagedServlet.getServlet(ManagedServlet.java:170)
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:84)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
    at co.gbt.chila.service.filters.CORSFilter.doFilter(CORSFilter.java:83)
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
    at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
    at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
    at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
    at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
    at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
    at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
    at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
    at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
    at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
    at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
    at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
    at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
    at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.jboss.resteasy.core.ResourceMethod from [Module "deployment.co.gbt.ear-0.1-SNAPSHOT.ear.co.gbt.service-0.1-SNAPSHOT.war:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
    ... 63 more

In my pom.xml I have the version:

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-multipart-provider</artifactId>
            <version>2.3.7.Final</version>
            <scope>provided</scope>
        </dependency>

And in my module.xml in the directory (wildfly-10.0.0.Final/modules/system/layers/base/org/jboss/resteasy/resteasy-multipart-provider/main) I have:

<module xmlns="urn:jboss:module:1.3" name="org.jboss.resteasy.resteasy-multipart-provider">

     <resources>
        <resource-root path="resteasy-multipart-provider-2.3.7.Final.jar"/>
    <resource-root path="resteasy-multipart-provider-2.3.2.Final-jandex.jar"/>
     </resources>

     <dependencies>
        <module name="javax.xml.bind.api"/>
        <module name="javax.api"/>
        <module name="javax.enterprise.api"/>
        <module name="javax.mail.api"/>
        <module name="javax.servlet.api"/>
        <module name="javax.ws.rs.api"/>
        <module name="org.apache.james.mime4j"/>
        <module name="org.jboss.resteasy.resteasy-jaxb-provider"/>
        <module name="org.jboss.resteasy.resteasy-jaxrs"/>
        <module name="org.jboss.logging"/>
    </dependencies>
</module>

Answer

Vishrant picture Vishrant · Sep 30, 2016

Go to your JBoss/Wildfly directory search for resteasy-jaxrs* you will get the version of resteasy library JBoss is using, add that version in pom.xml

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>3.0.18.Final</version>
    <!-- I have added 3.0.18.Final above as my JBoss was using this version -->
    <scope>provided</scope>
</dependency>

enter image description here