26

I'm trying to use RESTEasy as JAX-RS 2.0 client implementation. The problem is that I got runtime exception:

06-28 13:29:06.410: E/AndroidRuntime(5745): Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder
06-28 13:29:06.410: E/AndroidRuntime(5745):     at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:103)

So the newBuilder() method is searching for JerseyClientBuilder if I understand it correct. How can I tell the system to use RESTEasy instead?

Konstantin Milyutin
  • 11,946
  • 11
  • 59
  • 85
  • The answer by Carlo seems reasonable. Did you try it out? Did it resolve your problem? If so, please mark it as accepted. – aioobe Nov 13 '13 at 12:30

1 Answers1

29

Well, JAX-RS relies on the Service Provider convention. On the first lines of the newBuilder method you can read:

 Object delegate = FactoryFinder.find(JAXRS_DEFAULT_CLIENT_BUILDER_PROPERTY,
   JAXRS_DEFAULT_CLIENT_BUILDER); 

Where JAXRS_DEFAULT_CLIENT_BUILDER_PROPERTY is "javax.ws.rs.client.ClientBuilder"

In turn, FactoryFinder looks

  • first for the class name into META-INF/services/javax.ws.rs.client.ClientBuilder
  • then in the property javax.ws.rs.client.ClientBuilder into ${java.home}/lib/jaxrs.properties
  • finally into the System property javax.ws.rs.client.ClientBuilder.

So, to use RESTEasy, you should create a file

META-INF/services/javax.ws.rs.client.ClientBuilder

with the text:

org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder

which is the class name of the RESTEasy ClientBuilder

Carlo Pellegrini
  • 5,656
  • 40
  • 45
  • 7
    You can achieve the same by setting system property: `System.setProperty(ClientBuilder.JAXRS_DEFAULT_CLIENT_BUILDER_PROPERTY, "org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder");` or by creating a file `$java.home/lib/jaxrs.properties` – Krzysztof Wolny Sep 21 '15 at 11:36
  • 2
    Just a note that unlike `java.util.ServiceLoader`, the JAX-RS FactoryFinder does **not** allow #-comments in the `META-INF/services/javax.ws.rs.client.ClientBuilder` file. Discovered the painful way. – mwhidden Mar 02 '16 at 21:35