我有一个依赖于RESTEasy JAX RS Client
我将它作为依赖项添加到我的项目中:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.8.Final</version>
</dependency>
我可以正常编写代码,但是当我尝试编译时,我会收到这些错误:
java: cannot access javax.ws.rs.client.ClientBuilder
class file for javax.ws.rs.client.ClientBuilder not found
java: cannot access javax.ws.rs.core.Link
class file for javax.ws.rs.core.Link not found
java: cannot access javax.ws.rs.client.WebTarget
class file for javax.ws.rs.client.WebTarget not found
虽然我可以正常找到这些类,但我知道它们在我的maven repo中,如果我使用我的IDE查找它们,我可以访问它们,所以我知道它们存在。
我尝试将依赖范围更改为provided
和compile
只是为了测试它,但没有运气。
知道我可能缺少什么吗?
修改
相关的pom.xml
<modelVersion>4.0.0</modelVersion>
<artifactId>my-project-id</artifactId>
<name>MyProject Name</name>
<dependencies>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.8.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
类无法编译
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import my.project.representations.App;
public class Main {
public static void main(String[] args) {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(SERVER_URL);
String token = "access_token";
target.register(new BearerTokenFilter(token));
Admin admin = target.proxy(Admin.class);
Realm realm = admin.realm("realm_name");
for (App app : realm.apps().findAll()) {
System.out.println(app.getName());
}
}
}
答案 0 :(得分:5)
这是API类的地方:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
search.maven.org是你的朋友!
您已将resteasy-client.jar
依赖项以及其他所需依赖项标记为provided
,这意味着在执行或打包时, 不会包含在类路径中
删除所有这些依赖项上的<scope>
元素,很可能不正确。
查看<scope>
元素文档,确保这是您的意图。