最新泽西的例子不行 [英] Latest Jersey example does not work

查看:152
本文介绍了最新泽西的例子不行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经收到最新版本的球衣(Bundle-Version:2.13.0)和该版本的示例。然后我尝试(用于测试Restful服务 - \examples\helloworld-pure-jax-rs\src\main\java\org\glassfish\jersey\examples)Eclipse中的Hello World示例。结果是这样:

 Hello WorldJersey示例应用程序
线程mainjava.lang中的异常。 IllegalArgumentException:没有容器提供者支持类型接口com.sun.net.httpserver.HttpHandler
在org.glassfish.jersey.server.ContainerFactory.createContainer(ContainerFactory.java:87)
在org.glassfish。 jersey.server.internal.RuntimeDelegateImpl.createEndpoint(RuntimeDelegateImpl.java:71)
在org.glassfish.jersey.examples.helloworld.jaxrs.App.startServer(App.java:72)
在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版本1.8.0_25
Java(TM)SE运行时环境(build 1.8.0_25-b18)
Java HotSpot(TM)Client VM(build 25.25-b02 ,混合模式,共享)

任何想法可能是错或我错过了什么?



最佳
Klemens

解决方案

使用Maven和Eclipse



首先我从命令行尝试使用Maven(你需要安装Maven )。它的工作正常。



步骤:


  1. 已下载泽西2.13示例包 here

  2. 解压到 $ {myJerseyExampleLocation} (无论位置如何)

  3. cd $ {myJerseyExampleLocation} / jersey / examples / helloworld-pure-jax- rs

  4. mvn package - 下载所有依赖项并运行一个单元测试 HelloWorldTest 成功

  5. 要运行主应用程序 mvn exec:java 。这将通过执行程序 - >运行 App maven-plugin 列在pom的< plugins> 部分中。结果:

     应用程序启动。 
    尝试在浏览器中访问http:// localhost:8080 / helloworld。
    按Enter键停止应用程序...


  6. 从浏览器到 HTTP://本地主机:8080 / HelloWorld的。结果是 Hello World!

  7. 返回命令行,然后按Enter键停止服务器



    1. 从Eclipse:



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



      步骤:


      1. 解压缩

      2. 从Eclipse 导入 - > Maven - >现有的Maven项目浏览 helloworld-pure-jax-rs 并选择选择它完成

      3. 右键单击项目运行方式 - > Maven Build 。在目标的对话框字段类型 应用 - >运行。这将抓住所有的依赖关系。您应该获得构建成功以及成功的单元测试。

      4. 运行两个选项:

        • 打开应用程序类,右键单击它,运行为 - > Java应用程序。您应该在Eclipse控制台中获得相同的结果,提到Maven步骤5。

        • 右键单击项目,选择运行为 - > Maven Build (有两个选择您从上一步还没有选择的)。您将再次获得对话框。这允许您配置不同的运行配置。在目标中,键入 exec:java 。然后跑。您应该得到与上述相同的结果。


      在Eclipse环境中,使用1.7进行测试.0_65和1.8.0_20



      希望你能让它上班。让我知道你想出了什么。


      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

      解决方案

      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.

      这篇关于最新泽西的例子不行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆