gpt4 book ai didi

java - 无法实例化提供程序 org.glassfish.jersey.client.JerseyClientBuilder

转载 作者:行者123 更新时间:2023-12-03 21:00:43 25 4
gpt4 key购买 nike

我有一个实现 Jersey 客户端的 Android 项目。执行该行时出现异常:

Client client = ClientBuilder.newClient();

这是我的 gradle 依赖项:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'androidx.preference:preference:1.1.0'
implementation 'org.glassfish.jersey.core:jersey-client:2.28'
implementation 'org.glassfish.jersey.media:jersey-media-jaxb:2.28'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'com.sun.xml.bind:jaxb-core:2.3.0.1'
implementation 'com.sun.xml.bind:jaxb-impl:2.3.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

我在 Eclipse 中配置了一个项目,该项目也使用客户端,与 Android 项目具有相同的导入,效果很好。

这是一个异常(exception):
    java.lang.RuntimeException: java.lang.ClassNotFoundException: Provider org.glassfish.jersey.client.JerseyClientBuilder could not be instantiated: java.lang.reflect.InvocationTargetException
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:86)
at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:97)
at za.co.ezimax.client.RestExecutor.execute(RestExecutor.java:23)
at za.co.ezimax.client.RestClient.resetUserPassword(RestClient.java:43)
at za.co.ezimax.resetpassword.ResetPasswordActivity.resetPassword(ResetPasswordActivity.java:62)
at za.co.ezimax.resetpassword.ResetPasswordActivity.lambda$onCreate$0$ResetPasswordActivity(ResetPasswordActivity.java:42)
at za.co.ezimax.resetpassword.-$$Lambda$ResetPasswordActivity$yT5tltpKfEUxjtl2fzaBIET-T-Y.onClick(lambda)
at android.view.View.performClick(View.java:5106)
at android.view.View$PerformClick.run(View.java:20329)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5912)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
Caused by: java.lang.ClassNotFoundException: Provider org.glassfish.jersey.client.JerseyClientBuilder could not be instantiated: java.lang.reflect.InvocationTargetException
at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:94)
at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:185)
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:70)
at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:97) 
at za.co.ezimax.client.RestExecutor.execute(RestExecutor.java:23) 
at za.co.ezimax.client.RestClient.resetUserPassword(RestClient.java:43) 
at za.co.ezimax.resetpassword.ResetPasswordActivity.resetPassword(ResetPasswordActivity.java:62) 
at za.co.ezimax.resetpassword.ResetPasswordActivity.lambda$onCreate$0$ResetPasswordActivity(ResetPasswordActivity.java:42) 
at za.co.ezimax.resetpassword.-$$Lambda$ResetPasswordActivity$yT5tltpKfEUxjtl2fzaBIET-T-Y.onClick(lambda) 
at android.view.View.performClick(View.java:5106) 
at android.view.View$PerformClick.run(View.java:20329) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5912) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200) 
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:90)
at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:185) 
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:70) 
at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:97) 
at za.co.ezimax.client.RestExecutor.execute(RestExecutor.java:23) 
at za.co.ezimax.client.RestClient.resetUserPassword(RestClient.java:43) 
at za.co.ezimax.resetpassword.ResetPasswordActivity.resetPassword(ResetPasswordActivity.java:62) 
at za.co.ezimax.resetpassword.ResetPasswordActivity.lambda$onCreate$0$ResetPasswordActivity(ResetPasswordActivity.java:42) 
at za.co.ezimax.resetpassword.-$$Lambda$ResetPasswordActivity$yT5tltpKfEUxjtl2fzaBIET-T-Y.onClick(lambda) 
at android.view.View.performClick(View.java:5106) 
at android.view.View$PerformClick.run(View.java:20329) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5912) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200) 
Caused by: java.lang.NoClassDefFoundError: org.glassfish.jersey.model.internal.-$$Lambda$_yDVjAJwmPAQhS-G6o52AiDozCY
at org.glassfish.jersey.model.internal.CommonConfig.<clinit>(CommonConfig.java:68)
at org.glassfish.jersey.client.ClientConfig$State.<init>(ClientConfig.java:136)
at org.glassfish.jersey.client.ClientConfig.<init>(ClientConfig.java:491)
at org.glassfish.jersey.client.JerseyClientBuilder.<init>(JerseyClientBuilder.java:76)
at java.lang.reflect.Constructor.newInstance(Native Method) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:288) 
at javax.ws.rs.client.FactoryFinder.newInstance(FactoryFinder.java:90) 
at javax.ws.rs.client.FactoryFinder.find(FactoryFinder.java:185) 
at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:70) 
at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:97) 
at za.co.ezimax.client.RestExecutor.execute(RestExecutor.java:23) 
at za.co.ezimax.client.RestClient.resetUserPassword(RestClient.java:43) 
at za.co.ezimax.resetpassword.ResetPasswordActivity.resetPassword(ResetPasswordActivity.java:62) 
at za.co.ezimax.resetpassword.ResetPasswordActivity.lambda$onCreate$0$ResetPasswordActivity(ResetPasswordActivity.java:42) 
at za.co.ezimax.resetpassword.-$$Lambda$ResetPasswordActivity$yT5tltpKfEUxjtl2fzaBIET-T-Y.onClick(lambda) 
at android.view.View.performClick(View.java:5106) 
at android.view.View$PerformClick.run(View.java:20329) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5912) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200) 

最佳答案

This page可以帮助你更多。
从您的 resteasy 导入具有特定版本号的 RESTEasy 客户端。

<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.2.Final</version>
</dependency>
这将提供必要的类来构建客户端以发送 RESTful 请求。
如果仍然出现任何错误,请使用以下类:
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();
它将解决错误。

关于java - 无法实例化提供程序 org.glassfish.jersey.client.JerseyClientBuilder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57957521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com