Exception in thread “main” java.lang.NoClassDefFoundError: Could not initialize class com.sun.jersey.core.header.MediaTypes

后端 未结 3 639
陌清茗
陌清茗 2021-01-02 12:39

I\'m trying to run a jersey client and facing this issue.

WS Class:

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
im         


        
相关标签:
3条回答
  • 2021-01-02 13:15

    In my case I was not pulling in the jersey-core jar as a runtime dependency. Once i added it seemed to work fine.

    0 讨论(0)
  • 2021-01-02 13:23

    For followers, these (with mockito in this instance, but kind of generic):

    java.lang.NoClassDefFoundError: com/sun/jersey/spi/inject/Errors$Closure
    
    java.lang.NoClassDefFoundError: com/sun/jersey/core/header/LinkHeaders
    

    meant "you have a dependency on jersey-core 1.0.2 and also dependency on jersey-client 1.11" (need to match core with client versions more closely). Unfortunately "server" and "client" both use the "core" so in the end they practically all have to precisely match up :|

    0 讨论(0)
  • 2021-01-02 13:27

    Generally you would get this problem when your code compiled against jersey-bundle-1.8.jar and jsr311-api-0.9.jar. But here I can see you are using jsr311-api-1.1.1.jar. Then next problem would be older jar file would have been loaded by the application/web server. For eg: GlassFish 3.1 one comes with Jersy 1.5( which may take precedence over your libraries).

    Ideally you would need to check version of JSR-311 library is loaded (0.9 version of the jsr311-api jar is obsolete) in the server. And you should compile against jersey-bundle-1.8.jar, and run with jersey-bundle-1.8.jar and jsr311-api-1.1.1.jar

    0 讨论(0)
提交回复
热议问题