最新泽西州的例子不起作用

时间:2014-10-24 05:53:02

标签: java eclipse http jersey

我已经安装了最新版本的球衣(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)

知道什么可能是错的或我错过了什么?

最好

克莱门

2 个答案:

答案 0 :(得分:2)

使用Maven和Eclipse

首先,我从命令行(you need Maven installed)尝试使用Maven。它运作良好。

步骤:

  1. Jersey 2.13 Examples bundle
  2. 下载here
  3. 解压缩到${myJerseyExampleLocation}(无论位置如何)
  4. cd ${myJerseyExampleLocation}/jersey/examples/helloworld-pure-jax-rs
  5. mvn package - 已下载所有依赖项并成功运行了一个单元测试HelloWorldTest
  6. 运行主应用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...
    
  7. 从浏览器到http://localhost:8080/helloworld。结果为Hello World!
  8. 返回命令行并按Enter键停止服务器
  9. 来自Eclipse:

    我首先删除整个解压缩的示例,因为它已经构建完毕。我想从Eclipse开始从头开始。

    步骤:

    1. 解压缩的
    2. 来自Eclipse Import -> Maven -> Existing Maven Projects浏览helloworld-pure-jax-rs并选择选择Finish
    3. 右键点击项目Run As -> Maven Build。在goals字段中的对话框中输入package Apply -> Run。这将获取所有依赖项。您应该获得Build Successful以及成功的单元测试。
    4. 要运行的两个选项:
      • 打开App课程,右键单击并Run as -> Java Application。您应该在Eclipse控制台中获得与Maven Step 5相同的结果。
      • 右键点击项目,选择Run as -> Maven Build(有两个选择您尚未从上一步中选择的那个)。您将再次获得该对话框。这允许您配置不同的运行配置。在goals类型exec:java中。然后跑。你应该得到与上面相同的结果。
    5. 在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>

您可以根据您的环境更改版本。