Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
945 views
in Technique[技术] by (71.8m points)

rest - JAX-RS 2.0 change default implementation

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...