Reputation: 217
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
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
Reputation: 208944
With Maven and with Eclipse
First I tried with Maven from command line (you need Maven installed). It worked fine.
Steps:
${myJerseyExampleLocation}
(whatever the location may be)cd ${myJerseyExampleLocation}/jersey/examples/helloworld-pure-jax-rs
mvn package
- This downloaded all the dependencies and ran one unit test HelloWorldTest
successfullyTo 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...
http://localhost:8080/helloworld
. Result is Hello World!
From Eclipse:
I first delete the entire unzipped example, as it was already built. I wanted to do it from scratch from Eclipse.
Steps:
Import -> Maven -> Existing Maven Projects
Browse for helloworld-pure-jax-rs
and select select it Finish
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.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.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