user2737950
user2737950

Reputation: 217

Latest Jersey example does not work

I have isntalled the latest version of jersey (Bundle-Version: 2.13.0) and the examples for that version. Then I tried (for testing Restful services - \examples\helloworld-pure-jax-rs\src\main\java\org\glassfish\jersey\examples) the Hello World example in Eclipse. The result ist this:

"Hello World" Jersey Example Application
Exception in thread "main" java.lang.IllegalArgumentException: No container provider supports the type interface com.sun.net.httpserver.HttpHandler
at org.glassfish.jersey.server.ContainerFactory.createContainer(ContainerFactory.java:87)
at org.glassfish.jersey.server.internal.RuntimeDelegateImpl.createEndpoint(RuntimeDelegateImpl.java:71)
at org.glassfish.jersey.examples.helloworld.jaxrs.App.startServer(App.java:72)
at org.glassfish.jersey.examples.helloworld.jaxrs.App.main(App.java:88)

I thought the example should work out of the box as it does not use any specific http servers. Only

import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

My Java version is:

java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
Java HotSpot(TM) Client VM (build 25.25-b02, mixed mode, sharing)

Any idea what could be wrong or what I missed?

best Klemens

Upvotes: 4

Views: 2369

Answers (2)

lmiguelmh
lmiguelmh

Reputation: 3202

In my case I was following an example. Finally I only needed to add this dependency org.glassfish.jersey.containers jersey-container-jdk-http (remember the exception's message "No container provider supports the type interface com.sun.net.httpserver.HttpHandler"):

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-jdk-http</artifactId>
        <version>2.18</version>
    </dependency>

You could change the version according your environment.

Upvotes: 4

Paul Samsotha
Paul Samsotha

Reputation: 208944

With Maven and with Eclipse

First I tried with Maven from command line (you need Maven installed). It worked fine.

Steps:

  1. Downloaded Jersey 2.13 Examples bundle from here
  2. Unzipped to ${myJerseyExampleLocation} (whatever the location may be)
  3. cd ${myJerseyExampleLocation}/jersey/examples/helloworld-pure-jax-rs
  4. mvn package - This downloaded all the dependencies and ran one unit test HelloWorldTest successfully
  5. To run the main app mvn exec:java. This runs the App class through the exec-maven-plugin listed in the <plugins> section of the pom. Result:

    Application started.
    Try accessing http://localhost:8080/helloworld in the browser.
    Hit enter to stop the application...
    
  6. From browser to to http://localhost:8080/helloworld. Result is Hello World!
  7. Go back to command line and hit enter to stop server

From Eclipse:

I first delete the entire unzipped example, as it was already built. I wanted to do it from scratch from Eclipse.

Steps:

  1. Unzipped
  2. From Eclipse Import -> Maven -> Existing Maven Projects Browse for helloworld-pure-jax-rs and select select it Finish
  3. Right click on project Run As -> Maven Build. In the dialog in the goals field type package The Apply -> Run. This will grab all the dependencies. You should get a Build Successful along with a successful unit test.
  4. Two options to run:
    • Open the App class, right click it and Run as -> Java Application. You should get the same result in the Eclipse console as mention the Maven Step 5.
    • Right click on project, select Run as -> Maven Build (there are two select the one you haven't selected yet from the previous step). You will get the dialog again. This allows you to configure a different run configuration. In the goals type exec:java. Then run. You should get same result as above.

In Eclipse environment, tested with 1.7.0_65 and 1.8.0_20

Hopefully you can get it to work. Let me know what you come up with.

Upvotes: 2

Related Questions