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

白昼怎懂夜的黑 提交于 2019-11-30 13:36:44

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

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

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 :|

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!