[英]NoClassDefFoundError for Rest Client in Jboss EAP
I produce EAR sample App with REST client and deploy it on my notebook (JBoss EAP 6.3.0 with standalone configuration and binded any-address for public domain). 我使用REST客户端生成EAR示例应用程序,并将其部署在我的笔记本上(具有独立配置并为公共域绑定了任意地址的JBoss EAP 6.3.0)。 Following code is responsibility for producing REST response:
以下代码负责产生REST响应:
@Stateless
@Path("/users/list")
public class ListUsersREST {
@GET
@Produces("text/html")
public String getUsersList() {
return "TEST";
}
}
It's work fine through POSTMAM. 通过POSTMAM可以正常工作。 Probably this part of my example doesn't need any help.
我的示例的这一部分可能不需要任何帮助。
And now... I work on my second app deployed on my desktop (JBoss and configuration the same). 现在...我正在部署在桌面上的第二个应用程序(JBoss和配置相同)。 I have dependecies for JAVAEE7 API with contain JAVAX.WS.RS.* API.
我对包含JAVAX.WS.RS。* API的JAVAEE7 API有依赖性。 I'm trying to connect to this REST client and get response (like through POSTMAN):
我正在尝试连接到此REST客户端并获得响应(例如通过POSTMAN):
@Stateless
@Local(EJBTest.class)
public class EJBTestBean implements EJBTest {
@Override
public void getRestResponse() {
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://192.168.0.2:8080/demo/rest/users/list");
Response response = target.request(MediaType.TEXT_HTML).get();
String value = response.readEntity(String.class);
int status = response.getStatus();
response.close();
client.close();
System.out.println("REST RESPONSE: " + value);
System.out.println("REST Status: " + status);
}
}
...and this piece of code doesn't work. ...而这段代码不起作用。 I don't know why...
我不知道为什么
I'm getting the same Exception all the time... 我一直都在遇到同样的异常...
Caused by: java.lang.NoClassDefFoundError: javax/ws/rs/client/ClientBuilder 造成原因:java.lang.NoClassDefFoundError:javax / ws / rs / client / ClientBuilder
I was searching on google and trying many solution like 我在Google上搜索,并尝试了许多解决方案,例如
but with no effects... Please tell me what is going on. 但没有效果...请告诉我发生了什么。 What am I doing wrong?
我究竟做错了什么?
JBoss EAP 6 is Java EE 6 and you're deploying an app that requires Java EE 7. The JAX-RS client is only in Java EE 7. This should work if you tried your deployments on WildFly . JBoss EAP 6是Java EE 6,并且您正在部署需要Java EE 7的应用程序。JAX -RS客户端仅在Java EE 7中。如果您在WildFly上尝试了部署,那么它应该可以工作。
The reason you're dependencies don't seem to work is the server will us it's own JAX-RS dependencies over your own. 您的依赖项似乎无法正常工作的原因是服务器将让我们将其作为自己的JAX-RS依赖项。 You could potentially exclude the JAX-RS subsystem from your deployment which may work.
您可能会从您的部署中排除JAX-RS子系统,这可能会起作用。 You probably wouldn't be able to use JAX-RS endpoints though, only the client.
但是,可能只有客户端才能使用JAX-RS端点。
Your best bet though is to use Java EE 7 container, which WildFly 8 is. 最好的选择是使用Java EE 7容器,即WildFly 8。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.