GlassFish 4.0 / Jersey 2.0 - NoClassDefFoundError for JsonStructureBodyReader

旧街凉风 提交于 2019-12-05 23:11:46

If you're not using JSON (JSON Processing library) then you should remove jersey-media-json-processing module from the classpath of your client (which seems to be outside of GF). This module depends on jsonp-jaxrs.jar (+ javax.json.jar, javax.json-api.jar) which contains the JsonStructureBodyReader. The thing is that everytime the jersey-media-json-processing module is on a classpath Jersey tries to register JSON Processing providers via Auto-Discoverable mechanism. This means that in case of missing dependencies one would encounter an exteption similar to yours.

arso

Just remove the glassfish library from build path in eclipse. Then do add external jars, and add all the jars from the following folders in glassfish4 directory.

  1. C:\glassfish4\glassfish\modules
  2. C:\glassfish4\glassfish\modules\endorsed
  3. C:\glassfish4\mq\lib

Here's the client code I used to write REST client using JAX RS

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;


public class test {

    public static void main(String[] args) {

        Client client = ClientBuilder.newClient();
        String name = client.target("http://localhost:9999/MyResourceRestfulService/myresources/myresource")
          .request(MediaType.TEXT_PLAIN)
          .get(String.class);

        System.out.println(name);
    }

}

If you are using Glassfish 4.x as server and its libraries. You have to add javax.son.jar jsonp-jaxrs.jar

Both libraries are located in \glassfish\modules

If you are using a JUNIT test with MAVEN just add

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>jsonp-jaxrs</artifactId>
    <version>1.0</version>
    <scope>test</scope>
</dependency>

to your pom.xml

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