Java 最新的例子不起作用
我已经安装了jersey Bundle版本的最新版本:2.13.0以及该版本的示例。然后我尝试测试Restful服务-\examples\helloworld pure jax rs\src\main\java\org\glassfish\jersey\examples Eclipse中的Hello World示例。结果是:Java 最新的例子不起作用,java,eclipse,http,jersey,Java,Eclipse,Http,Jersey,我已经安装了jersey Bundle版本的最新版本: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.IllegalA
"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)
你知道我可能错了什么或错过了什么吗
最好的
克莱门斯带着梅文和日食 首先,我尝试从命令行使用Maven。它工作得很好 步骤: 下载自 解压缩到${myJerseyExampleLocation}无论位置是什么 cd${myJerseyExampleLocation}/jersey/examples/helloworld纯jax-rs mvn包-下载了所有依赖项并成功运行了一个单元测试HelloWorldTest 要运行主应用程序mvn exec:java。这将通过pom部分中列出的运行应用程序类。结果:
Application started.
Try accessing http://localhost:8080/helloworld in the browser.
Hit enter to stop the application...
从浏览器到http://localhost:8080/helloworld. 结果是世界你好!
返回命令行并按enter键停止服务器
从Eclipse:
我首先删除了整个解压示例,因为它已经构建好了。我想从Eclipse开始从头开始做
步骤:
拉开拉链
从EclipseImport->Maven->ExistingMaven项目浏览HelloWorldPureJAX rs并选择SelectItFinish
右键单击项目运行方式->Maven构建。在目标字段的对话框中,键入应用->运行包。这将获取所有依赖项。您应该获得成功的构建和成功的单元测试。
要运行的两个选项:
打开应用程序类,右键单击它并以->Java应用程序的方式运行。您应该在Eclipse控制台中获得与Maven步骤5相同的结果。
右键单击project,选择RunAs->Maven Build有两个选项,选择上一步中尚未选择的选项。您将再次获得该对话框。这允许您配置不同的运行配置。在目标中键入exec:java。然后跑。你应该得到与上面相同的结果。
在Eclipse环境中,使用1.7.0_65和1.8.0_20进行测试
希望你能让它工作。让我知道你的想法。在我的例子中,我是在遵循一个例子。最后,我只需要添加这个依赖项org.glassfish.jersey.containers jersey container jdk http记住异常消息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>
您可以根据您的环境更改版本。如果您缺少目标文件夹,您应该首先生成项目。非常感谢!现在工作了。我安装了最新的Eclipse版本,并遵循了您的步骤。