1

I have a code that has a dependency on the RESTEasy JAX RS Client

I added it as a dependency to my project like this:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.0.8.Final</version>
</dependency>

I can write the code normally, but when I try to compile, I get these errors:

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

Although I can find these classes normally, I know they are in my maven repo, and if I look them up using my IDE, I can access them, so I know they exist.

I tried changing the dependency scope to provided and compile just for the sake of testing it out, but with no luck.

Any idea what I might be missing?

EDIT

relevant 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>

class failing to compile

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());
        }

    }

}
11
  • How are you compiling? Commented Jul 18, 2014 at 14:49
  • I compiled it with the IDE (IntelliJ IDEA), and when I saw this error I tried compiling through maven mvn clean install which showed the same problem Commented Jul 18, 2014 at 14:49
  • The .pom please and one source failing source file please, if possible minimal failing example. Commented Jul 18, 2014 at 14:51
  • I'm sorry, I'm not sure what you want me to post here, could you elaborate a little bit more? Commented Jul 18, 2014 at 14:52
  • I would like to see the "pom.xml" file, please remove irrelevant stuff and one ".java" file which fails to compile. Commented Jul 18, 2014 at 14:54

1 Answer 1

5

You are not including a dependency to what it is complaining about:

This is where the API classes are:

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0</version>
</dependency>

search.maven.org is your friend!

The following isn't correct as well.

You have marked the resteasy-client.jar dependency, as well as the others, that you need as provided which means it will not be included on the classpath when executed or packaged.

Remove the <scope> element on all those dependencies, it is most likely not correct.

Review the <scope> element documentation and make sure this is what you intend.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried adding jaxrs-api and resteasy-jaxrs and it worked, which is weird because I thought I didn't have to do that explicitly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.