You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Konrad Windszus (JIRA)" <ji...@apache.org> on 2012/12/07 19:01:26 UTC

[jira] [Comment Edited] (CXF-4686) NoClassDefFoundError for javax.ws.rs.core.MediaType in OSGi environment

    [ https://issues.apache.org/jira/browse/CXF-4686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13526580#comment-13526580 ] 

Konrad Windszus edited comment on CXF-4686 at 12/7/12 6:00 PM:
---------------------------------------------------------------

Thanks for your input. I think using something like proposed in http://stackoverflow.com/questions/10458378/how-can-i-make-a-java-lang-reflect-proxy-from-two-separate-classloaders might indeed fix our issue. I don't know though how the servicemix jsr311-api is different from the regular jsr311-api. I just created my own bundle, containing all relevant CXF JARs as well as JAX-RS API itself. I don't rely on the servicemix bundle.
                
      was (Author: kwin):
    Thanks for your input, indeed I think using something like proposed in http://stackoverflow.com/questions/10458378/how-can-i-make-a-java-lang-reflect-proxy-from-two-separate-classloaders might fix our issue. I don't how the service mix jsr311-api is different though. I just created my own bundle, containing all relevant CXF JARs as well as JAX-RS itself.
                  
> NoClassDefFoundError for javax.ws.rs.core.MediaType in OSGi environment
> -----------------------------------------------------------------------
>
>                 Key: CXF-4686
>                 URL: https://issues.apache.org/jira/browse/CXF-4686
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.6.2
>         Environment: Apache Felix
>            Reporter: Konrad Windszus
>
> I try to create a JAX-RS client from bundle a with the help of an annotated class like
> {code}
> // Jax-RS client
> ProductClientProxy productProxy = JAXRSClientFactory.create(<url>, ProductClientProxy.class);
> {code}
> CXF and JAX-RS are both exposed from another bundle (bundle b). The problem is during runtime I get the following exception
> {noformat}
> java.lang.NoClassDefFoundError: javax.ws.rs.core.MediaType not found by <bundle a> [368]
> 	at $Proxy205.<clinit>(Unknown Source)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
> 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
> 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
> 	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> 	at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:588)
> 	at org.apache.cxf.common.util.ProxyHelper.getProxyInternal(ProxyHelper.java:45)
> 	at org.apache.cxf.common.util.ProxyHelper.getProxy(ProxyHelper.java:50)
> 	at org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.createWithValues(JAXRSClientFactoryBean.java:302)
> 	at org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.create(JAXRSClientFactoryBean.java:243)
> 	at org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory.java:86)
> 	at org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory.java:72)
> 	at org.apache.cxf.jaxrs.client.JAXRSClientFactory.create(JAXRSClientFactory.java:49)
> 	at <code line listed above>
> {noformat}
> The problem is that CXF tries to instanciate a Client in JAXRSClientFactoryBean (line 302, leveraging the classloader of the client bundle (bundle a), not with the classloader of the CXF bundle(bundle b)). Unfortunately the classloader of the bundle a does not import the package javax.ws.rs.core, and therefore this NoClassDefFoundError is thrown. 
> As a workaround we explicitly import the package javax.ws.rs.core in bundle a. Although I don't know how to fix it from your site, it would be great if the necessary packages would automatically detected (in this case by the maven-bundle-plugin) or you use another classloader to load the org.apache.cxf.jaxrs.client.Client interface, or you remove all the dependencies on other packages from the Client interface.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira