[SOLVED] java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder

If you are using RESTEasy 3.x.y which has been support for JAX-RS 2.0, and you are trying to write RESTEasy client then you can face this exception. Full stack trace might look like this:

Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
	at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:103)
	at test.jaxrs2.Demo_JAXRS_2_Example.main(Demo_JAXRS_2_Example.java:14)
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:113)
	at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:206)
	at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
	... 1 more
Random exceptions
Random exceptions

Root cause

Probably you are following trying to wrire the client code as follows:

	Client client = ClientBuilder.newBuilder().build();
	WebTarget target = client.target("http://localhost:8080/RESTEasyApplication/user-management/users");
	Response response = target.request().get();
	String users = response.readEntity(String.class);

JAX-RS relies on the Service Provider convention. So, you will need to do multiple things to get it work. Follow below thread for more insight:

https://stackoverflow.com/questions/17366266/jax-rs-2-0-change-default-implementation

Solution

Import RESTEasy client with specific version number as of your resteasy.

<dependency>
	<groupId>org.jboss.resteasy</groupId>
	<artifactId>resteasy-client</artifactId>
	<version>3.0.2.Final</version>
</dependency>

This will provide necessary classes to build client for sending RESTful requests.

If still you get any error then use following classes :

	ResteasyClient client = new ResteasyClientBuilder().build();
	ResteasyWebTarget target = client.target("http://localhost:8080/RESTEasyApplication/user-management/users");
	Response response = target.request().get();
	String value = response.readEntity(String.class);
	System.out.println(value);
	response.close();  

It will solve the error.

Happy Learning !!

Was this post helpful?

Join 7000+ Awesome Developers

Get the latest updates from industry, awesome resources, blog updates and much more.

* We do not spam !!

8 thoughts on “[SOLVED] java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder”

  1. This issue has taken my 1 day :(.
    With REstEasy 4.4 version, RESTEasyClientBuilder is abstract class so we need to pass RESTEasyClientBuilderImpl class as
    -Djavax.ws.rs.client.ClientBuilder=org.jboss.resteasy.client.jaxrs.ResteasyClientBuilderImpl

    Reply
  2. Hello ,

    I tried above code in my project but i am facing issue again

    ResteasyClient client=new ResteasyClientBuilder().build();
           ResteasyWebTarget target=client.target("xxxxxxxxxxxxxxxxxxxxxxxx");
           Response response = target.request(MediaType.APPLICATION_JSON)
                               .post(Entity.entity(md, MediaType.APPLICATION_JSON));
    Exception in thread "main" java.lang.NoSuchFieldError: INSTANCE
    	at org.apache.http.conn.ssl.SSLConnectionSocketFactory.(SSLConnectionSocketFactory.java:146)
    	at org.jboss.resteasy.client.jaxrs.HttpClientBuilder43.initDefaultEngine43(HttpClientBuilder43.java:111)
    	at org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder.build(ResteasyClientBuilder.java:422)
    	at client.ClientClassSender.postListValueInJSON(ClientClassSender.java:54)
    	at webservice.WebService.main(WebService.java:43)
    BUILD STOPPED (total time: 6 seconds)
    Reply
  3. I’m getting this errror

    Exception in thread “main” java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;

    Reply

Leave a Comment

HowToDoInJava

A blog about Java and related technologies, the best practices, algorithms, and interview questions.