且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JEE无法运行JAX-RS WebService骨架应用程序

更新时间:2022-03-10 06:59:22

Glassfish 4使用Jersey 2.x.您应该相应地更改依赖关系和web.xml配置。对于依赖项,您可以使用

Glassfish 4 uses Jersey 2.x. You should change the dependency and web.xml configuration accordingly. For the dependency, you can use

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>${jersey2.version}</version>
    <scope>provided</scope>
</dependency>

和配置

<servlet>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.wld.rest</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>jersey-serlvet</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

最近看到很多人(使用Glassfish和泽西岛)的一个问题是事实上,Glassfish使用较旧版本的Jersey(旧的2.x版旧版)。截至目前的最新情况是2.17。 Glassfish使用2.x系列中第一个附近的东西。因此新功能似乎存在一些兼容性问题。

One "gotcha" a see a lot of people (who are using Glassfish and Jersey) lately is the fact that Glassfish uses an older version of Jersey (old in the sense of an older 2.x version). The latest as of now is 2.17. Glassfish uses something near the first one in the 2.x family. So there seems to be some compatibility problems with new features.

我肯定会关注的一件事是在GlassFish 4中更新Jersey 2 。这是一篇非常好的文章。你可能不会遇到任何问题简单的启动应用程序,但有了新功能,尝试升级Glassfish中的泽西岛可能有所帮助。

One thing I would definitely look into is Updating Jersey 2 in GlassFish 4. It's a pretty good article. You may not face any issues will simple startup apps, but with new features, trying to upgrade Jersey in Glassfish might help.

另一件事,记得摆脱你的泽西岛1.x依赖。这两者完全不兼容。另请注意Maven依赖项中的提供的范围。由于Glassfish已经内置了Jersey,我们只是使用内部依赖项。

Another thing, remember to get rid of your Jersey 1.x dependencies. The two are completely incompatible. Also notice the provided scope in the Maven dependency. Since Glassfish has Jersey built in already, we are just using the internal dependencies.

保持方便的一件好事是 Jersey 2.x文档

Also a good thing to keep handy is the Jersey 2.x Documentation

哦,还有一件事。泽西岛有一个原型,可以帮助您轻松上手。在Netbeans中,只需

Oh and one other thing. Jersey has an archetype that helps you get started easily. In Netbeans just do


  1. 新项目

  2. Maven→来自Archetype的项目

  3. 搜索 jersey-quickstart-webapp

  4. 选择具有该组的一个ID org.glassfish.jersey.archetypes

  5. 应显示最新版本。

  1. New Project
  2. Maven → Project from Archetype
  3. Search jersey-quickstart-webapp
  4. Select the one with the Group ID org.glassfish.jersey.archetypes
  5. The latest version should be displayed.