0

I do not understand why when I am creating a JAX-RS client inside an EJB, cannot get the implementation of JAX-RS. I believe that it is assumed that an application server like Glassfish 3.1 should provide an JAX-RS implementation like Jersey, and I should not add it like dependency, but it can not find it.

The error is a java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder and I think that It should not be necessary add Jersey to the classpath because Glassfish must provide it.

The code that generates the error is

Client client = ClientBuilder.newClient();

This code is inside an EJB method, and my test case is:

EJBContainer container = EJBContainer.createEJBContainer();
MyService service = (MyService) container.getContext().lookup("java:global/classes/MyService");
service.create(null);

The dependencies in the pom.xml file looks like:

<dependencies>
    <dependency>
        <groupId>org.glassfish.extras</groupId> 
        <artifactId>glassfish-embedded-all</artifactId> 
        <version>3.1.1</version> 
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>log4j-over-slf4j</artifactId>
        <version>1.7.7</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.12</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

The packaging is a WAR file, I think that should not be a problem.

rvillablanca
  • 1,606
  • 3
  • 21
  • 34

1 Answers1

1

GlassFish 3.1 is a JavaEE 6 implementation which implements JAX-RS 1.1

You need to update to GlassFish 4.1 to get the JAX-RS 2.0 implementation that you are using (according to the javaee-api 7.0 dependency that you have included).

In fact javax.ws.rs.client.ClientBuilder was added in JAX-RS 2.0.

Steve C
  • 18,876
  • 5
  • 34
  • 37
  • According to http://www.oracle.com/technetwork/java/javaee/tech/javaee6technologies-1955512.html, jax-rs belongs to JavaEE 6. – rvillablanca Dec 02 '15 at 02:14
  • But you are attempting to use Java EE 7 APIs in your pom.xml? – Steve C Dec 02 '15 at 02:42
  • Yes, i am using jee 7 api. I dont know how i can do the test using a jee 7 ejb container, however my code should work in jee 6/7 container – rvillablanca Dec 02 '15 at 02:47
  • Hey @Steve C, you are right!, The jax-rs client api is in jee7, in jee6 there is not client api http://www.oracle.com/technetwork/articles/java/jaxrs20-1929352.html – rvillablanca Dec 02 '15 at 12:49
  • Ah sorry, I had not seen your response updated, you are right!. Thanks! – rvillablanca Dec 02 '15 at 12:52