Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restful webservices - NoClassDefFoundError: org/glassfish/jersey/ExtendedConfig

So I created the webservice in this thread and finally I managed to solve the problem. Now I'm trying to consume this webservice.

I've created a new web project on Netbeans and I'm using Apache Tomcat. Here's the code to consume the webservice. I've gone through some tutorials to produce this code.

package com.client;

import java.net.URI;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;

import org.glassfish.jersey.client.ClientConfig;

public class HelloClient {


  public void consumeRest(){

    ClientConfig config = new ClientConfig();

    Client client = ClientBuilder.newClient(config);

    WebTarget target = client.target(getBaseURI());

    System.out.println("response");

    System.out.println(target.path("hello").path("world").request()

    .accept(MediaType.APPLICATION_JSON).get(Response.class)

    .toString());

    }


  private URI getBaseURI() {

    return UriBuilder.fromUri("http://localhost:8084/restful_example").build();

  }

} 

I've created a main class to call the consume method. When I run it, I get this exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/glassfish/jersey/ExtendedConfig
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at com.client.HelloClient.consumeRest(HelloClient.java:29)
    at com.client.main.main(main.java:16)
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.ExtendedConfig
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 14 more
Java Result: 1

I guess it's a libs problem but I couldn't solve it. Using only JAX-RS 2.0 is not sufficient, so I'm also using Jersey libs.

What's wrong here? Is this the correct way to consume this webservice? I've seen some other versions and I'm not sure which one to use.

like image 739
user3641702 Avatar asked May 18 '15 13:05

user3641702


1 Answers

Seems that you are missing the jersey-common jar from your classpath

You can download the jar on maven at the following url: - http://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-common

like image 189
Kevin Crain Avatar answered Oct 13 '22 11:10

Kevin Crain