【发布时间】:2015-11-17 21:21:33
【问题描述】:
简单的网络服务部署在网络服务器上,其网址为
http://localhost:8080/jersey-example-new/rs/account/details/param
现在我顺便尝试通过 Jersey 客户端使用这个服务:
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(UriBuilder.fromUri("http://localhost:8080/jersey-example-new/rs/account/details/andy").build());
项目依赖:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.1.3</version>
</dependency>
我得到错误:
Exception in thread "main" java.lang.AbstractMethodError:
javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119) at
com.javacodegeeks.jersey.main.RestClient.main(RestClient.java:21)
【问题讨论】:
-
当你运行它时,你的类路径中有一些 api-jar 吗?即使您针对 api 进行编译,也必须使用实现运行。
-
@folkol 我已经用我拥有的依赖项更新了这个问题。
-
你的程序运行得如何?您确定执行代码时 api-jar 不在类路径中吗?
-
@folkol 我通过 Eclipse 作为主要方法运行它。
-
Andreas Schwarz:api jar 不应该在那里。删除“javax.ws.rs-api”,看看是否有效。