简体   繁体   English

Jersey java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

[英]Jersey java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

I'm trying to make a web-service with Tomcat and Eclipse using jersey library.我正在尝试使用 jersey 库使用 Tomcat 和 Eclipse 制作网络服务。 This is my service class:这是我的服务类:

package com.gontuseries.university;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;


@Path("/university")
public class UniversityRestWs {

    @GET
    @Produces(MediaType.TEXT_HTML)
    public String getHtmlUniversityInfo(){
        return "<html><body>test</body></html>";
    }

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getTextUniversityInfo(){
        return "test";
    }
}

And this is file web.xml这是文件 web.xml

 <servlet>
 <servlet-name>Jersey REST Service</servlet-name>
 <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
 <init-param>
 <param-name>com.sun.jersey.config.property.packages</param-name>
 <param-value>com.gontuseries.university</param-value>
 </init-param>
 </servlet>
 <servlet-mapping>
 <servlet-name>Jersey REST Service</servlet-name>
 <url-pattern>/rest/*</url-pattern>
 </servlet-mapping>

When i test my service i get java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer I downloaded jersey from https://jersey.java.net/download.html当我测试我的服务时,我得到 java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer 我从https://jersey.java.net/download.html下载了球衣

Can someone help me?有人能帮我吗? Thanks谢谢

For me the problem was that the server had no jars in the lib folder.对我来说,问题是服务器的 lib 文件夹中没有 jar。 Make sure it has access to all dependencies in: project -> properties -> development assembly -> add -> java build path entries.确保它可以访问以下所有依赖项:项目 -> 属性 -> 开发程序集 -> 添加 -> java 构建路径条目。

We need to use provide build path to Eclipse .我们需要使用提供到 Eclipse 的构建路径 That must resolve issue.那必须解决问题。

Make sure it has access to all dependencies in: project -> properties -> development assembly -> add -> java build path entries --> maven dependency确保它可以访问以下所有依赖项:项目 -> 属性 -> 开发程序集 -> 添加 -> java 构建路径条目 -> maven 依赖项

jersey bundle dependency球衣包依赖

<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-servlet</artifactId>
   <version>1.17</version>
<dependency>

If you are using maven, best few simple steps will work your application如果您使用的是 maven,那么最好的几个简单步骤将适用于您的应用程序

Man, I had the same problem.伙计,我遇到了同样的问题。 I solve id adding the jersey-servlet-1.18.jar to the WEB-INF/lib.我解决了将 jersey-servlet-1.18.jar 添加到 WEB-INF/lib 的 id。 Then, this folder saw like this:然后,这个文件夹是这样的:

.
Remember, add all this jars to yout build-path请记住,将所有这些 jars 添加到您的构建路径中

Are you using Jersey 2.x?您使用的是 Jersey 2.x 吗? If so, the ServletContainer class has been moved to another package.如果是,则ServletContainer类已移至另一个包。 This article has some good info on how to change your web.xml when migrating from Jersey 1.7 to 2.x: https://java.net/projects/jersey/lists/users/archive/2013-06/message/91 .本文提供了一些关于如何在从 Jersey 1.7 迁移到 2.x 时更改 web.xml 的好信息: https : //java.net/projects/jersey/lists/users/archive/2013-06/message/91

com.sun.jersey.spi.container.servlet.ServletContainer类包含在“jersey-servlet.jar”中,因此您应该将它与“jersey-server.jar”一起放到 WEB-INF/lib 中。

I got the same error -"java.lang.ClassNotFoundException : com.sun.jersey.spi.container.servlet.ServletContainer", while trying to execute restful jersey web service in tomcat from eclipse.我遇到了同样的错误 - “java.lang.ClassNotFoundException : com.sun.jersey.spi.container.servlet.ServletContainer”,同时尝试从 Eclipse 的 tomcat 中执行 restful jersey web 服务。

Following steps helped me to resolve the issue :以下步骤帮助我解决了这个问题:

  • Correct the maven dependency to right version of dependent jars将 Maven 依赖更正为依赖 jar 的正确版本

     <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.19</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-servlet</artifactId> <version>1.19</version> </dependency>
  • Right click on the eclipse project -> Maven -> Update Project右键单击eclipse项目-> Maven -> 更新项目

  • Ensure in eclipse properties development assembly is configured correctly.确保 eclipse 属性开发程序集配置正确。 Right click on project - Properties -> development assembly -> Add -> java build path entries -> maven dependency右键项目-属性->开发程序集->添加->java构建路径条目->maven依赖

If you are using JERSEY-jaxrs-ri-2.9 version zip, Use the given below in WEB.XML file.如果您使用的是 JERSEY-jaxrs-ri-2.9 版本 zip,请在 WEB.XML 文件中使用下面给出的内容。

<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
  <param-name>jersey.config.server.provider.packages</param-name>
   ......
</init-param>

I was getting this error in an Eclipse project that had previously worked fine, running on Tomcat 7.0.我在 Eclipse 项目中遇到此错误,该项目以前运行良好,在 Tomcat 7.0 上运行。 Eventually I solved it by removing the project from Tomcat and adding it back again.最终我通过从 Tomcat 中删除项目并重新添加它来解决它。

Above provided solutions are correct but even after making these changes i was getting this error.上面提供的解决方案是正确的,但即使进行了这些更改,我还是收到了这个错误。 So what I did was removed all the maven downloaded Jersey jars and update Project again with new maven dependency and that resolved my issue所以我所做的是删除所有 maven 下载的 Jersey jar 并使用新的 maven 依赖项再次更新项目,这解决了我的问题

We get this error because of build path issue and outdated dependency names.Latest one's start from org.glassfish and not com.sun.After replacing with latest dependencies for 2.0, You should add "Server Runtime" libraries in Build Path.我们收到此错误是因为构建路径问题和过时的依赖项名称。最新的从 org.glassfish 而不是 com.sun 开始。替换为 2.0 的最新依赖项后,您应该在构建路径中添加“服务器运行时”库。

"java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer" “java.lang.ClassNotFoundException:com.sun.jersey.spi.container.servlet.ServletContainer”

Please follow below steps to resolve class not found exception.请按照以下步骤解决找不到类的异常。

Right click on project --> Build Path --> Build Path --> Add Library --> Server Runtime --> Apache Tomcat v7.0右键单击项目--> 构建路径--> 构建路径--> 添加库--> 服务器运行时--> Apache Tomcat v7.0

Thanks, Sachin GN谢谢,萨钦 GN

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jersey 错误 java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer - Jersey error java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer 将Liferay jersey portlet部署到Tomcat会引发异常java.lang.ClassNotFoundException:com.sun.jersey.spi.container.servlet.ServletContainer - Deploying Liferay jersey portlet to Tomcat throws exception java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer 无法在Tomcat 7上部署Restful简单代码。错误java.lang.ClassNotFoundException:com.sun.jersey.spi.container.servlet.ServletContainer - Unable to deploy Restful simple code on Tomcat 7. error java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer 春季启动com.sun.jersey.spi.container.servlet.ServletContainer - spring boot com.sun.jersey.spi.container.servlet.ServletContainer Spring Jersey 2.7:java.lang.ClassNotFoundException:com.sun.jersey.spi.spring.container.servlet.SpringServlet - Spring Jersey 2.7: java.lang.ClassNotFoundException: com.sun.jersey.spi.spring.container.servlet.SpringServlet 如何配置jersey以避免com.sun.jersey.spi.container.servlet.ServletContainer出现问题? - How to configure jersey to avoid com.sun.jersey.spi.container.servlet.ServletContainer giving problems? java.lang.ClassNotFoundException:com.sun.jersey.server.impl.container.servlet.ServletAdaptor - java.lang.ClassNotFoundException: com.sun.jersey.server.impl.container.servlet.ServletAdaptor java.lang.ClassNotFoundException:org.glassfish.jersey.servlet.ServletContainer - java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer java.lang.ClassNotFoundException:com.sun.jersey.spi.service.ComponentProvider - java.lang.ClassNotFoundException: com.sun.jersey.spi.service.ComponentProvider java.lang.ClassNotFoundException:com.sun.jersey.core.spi.factory.ResponseImpl REST-FUL Webservices - java.lang.ClassNotFoundException: com.sun.jersey.core.spi.factory.ResponseImpl REST-FUL Webservices
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM