最新泽西的例子不行 [英] Latest Jersey example does not work
问题描述
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 )。它的工作正常。
步骤:
- 已下载泽西2.13示例包从 here
- 解压到
$ {myJerseyExampleLocation}
(无论位置如何) -
cd $ {myJerseyExampleLocation} / jersey / examples / helloworld-pure-jax- rs
-
mvn package
- 下载所有依赖项并运行一个单元测试HelloWorldTest
成功 -
要运行主应用程序
mvn exec:java
。这将通过执行程序 - >运行App
maven-plugin 列在pom的< plugins>
部分中。结果:应用程序启动。
尝试在浏览器中访问http:// localhost:8080 / helloworld。
按Enter键停止应用程序...
- 从浏览器到
HTTP://本地主机:8080 / HelloWorld的
。结果是Hello World!
- 返回命令行,然后按Enter键停止服务器
- 解压缩
- 从Eclipse
导入 - > Maven - >现有的Maven项目
浏览helloworld-pure-jax-rs
并选择选择它完成
- 右键单击项目
运行方式 - > Maven Build
。在目标的对话框
字段类型包
应用 - >运行
。这将抓住所有的依赖关系。您应该获得构建成功
以及成功的单元测试。 - 运行两个选项:
- 打开
应用程序
类,右键单击它,运行为 - > Java应用程序
。您应该在Eclipse控制台中获得相同的结果,提到Maven步骤5。 - 右键单击项目,选择
运行为 - > Maven Build
(有两个选择您从上一步还没有选择的)。您将再次获得对话框。这允许您配置不同的运行配置。在目标
中,键入exec:java
。然后跑。您应该得到与上述相同的结果。
- 打开
- Downloaded Jersey 2.13 Examples bundle from here
- Unzipped to
${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 testHelloWorldTest
successfullyTo run the main app
mvn exec:java
. This runs theApp
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...
- From browser to to
http://localhost:8080/helloworld
. Result isHello World!
- Go back to command line and hit enter to stop server
- Unzipped
- From Eclipse
Import -> Maven -> Existing Maven Projects
Browse forhelloworld-pure-jax-rs
and select select itFinish
- Right click on project
Run As -> Maven Build
. In the dialog in thegoals
field typepackage
TheApply -> Run
. This will grab all the dependencies. You should get aBuild Successful
along with a successful unit test. - Two options to run:
- Open the
App
class, right click it andRun 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 thegoals
typeexec:java
. Then run. You should get same result as above.
- Open the
从Eclipse:
我首先删除整个解压缩的示例,因为它已经构建。我想从头开始从Eclipse开始。
步骤:
在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:
From Eclipse:
I first delete the entire unzipped example, as it was already built. I wanted to do it from scratch from Eclipse.
Steps:
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屋!