我已经安装了最新版本的球衣(Bundle-Version:2.13.0)以及该版本的示例。然后我尝试(用于测试Restful服务 - \ examples \ helloworld-pure-jax-rs \ src \ main \ java \ org \ glassfish \ jersey \ examples)Eclipse中的Hello World示例。结果如下:
"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)
我认为该示例应该开箱即用,因为它不使用任何特定的http服务器。仅
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
我的Java版本是:
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)
知道什么可能是错的或我错过了什么?
最好克莱门
答案 0 :(得分:2)
使用Maven和Eclipse
首先,我从命令行(you need Maven installed)尝试使用Maven。它运作良好。
步骤:
${myJerseyExampleLocation}
(无论位置如何)cd ${myJerseyExampleLocation}/jersey/examples/helloworld-pure-jax-rs
mvn package
- 已下载所有依赖项并成功运行了一个单元测试HelloWorldTest
运行主应用mvn exec:java
。这会通过pom的App
部分中列出的exec-maven-plugin运行<plugins>
课程。结果:
Application started.
Try accessing http://localhost:8080/helloworld in the browser.
Hit enter to stop the application...
http://localhost:8080/helloworld
。结果为Hello World!
来自Eclipse:
我首先删除整个解压缩的示例,因为它已经构建完毕。我想从Eclipse开始从头开始。
步骤:
Import -> Maven -> Existing Maven Projects
浏览helloworld-pure-jax-rs
并选择选择Finish
Run As -> Maven Build
。在goals
字段中的对话框中输入package
Apply -> Run
。这将获取所有依赖项。您应该获得Build Successful
以及成功的单元测试。App
课程,右键单击并Run as -> Java Application
。您应该在Eclipse控制台中获得与Maven Step 5相同的结果。Run as -> Maven Build
(有两个选择您尚未从上一步中选择的那个)。您将再次获得该对话框。这允许您配置不同的运行配置。在goals
类型exec:java
中。然后跑。你应该得到与上面相同的结果。在Eclipse环境中,使用1.7.0_65和1.8.0_20进行测试
希望你能让它发挥作用。让我知道你的想法。
答案 1 :(得分:2)
就我而言,我是在跟随一个例子。最后,我只需要添加此依赖项org.glassfish.jersey.containers
jersey-container-jdk-http
(请记住异常的消息“No container 提供程序支持类型接口com.sun.net .httpserver.HttpHandler“):
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jdk-http</artifactId>
<version>2.18</version>
</dependency>
您可以根据您的环境更改版本。