当前位置: 首页 > 知识库问答 >
问题:

Tomcat 7 ClassNotFoundException:org.glassfish.jersey.servlet.ServletContainer

杭志泽
2023-03-14

我试图在OS X 10.10上运行apache 7.0.57的RESTful服务,使用Jersey 2.13和JDK 8。我已经部署了apache,它开始正常。我编写了一个简单的RESTfull服务,并将其部署到WEB-INF/类。网络。已配置xml。但是,当我尝试启动tomcat时,restful资源错误如下

SEVERE: Servlet /resttest threw load() exception
java.lang.ClassNotFoundException:
       org.glassfish.jersey.servlet.ServletContainer

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:506)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:488)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:115)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1148)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5231)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5518)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1245)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1895)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

网.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>TestREST</display-name>
 
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>
        org.glassfish.jersey.servlet.ServletContainer
    </servlet-class>
    <init-param>    
         <param-name>jersey.config.server.provider.packages</param-name>
         <param-value>org.sample.resources</param-value>
   </init-param>
   <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
     <servlet-name>Jersey REST Service</servlet-name>
     <url-pattern>/rest/*</url-pattern>
   </servlet-mapping>
</web-app>

java 类

package org.sample.resources;

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

@Path("/xyz")
public class TestGet {

  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String sayHello() {
      return "Hello Jersey";
  }
}

我甚至已经将 jersey-container-servlet-core 的内容提取.jar到 WEB-INF/classes 目录中,但在重新启动时,我仍然收到相同的错误。

有什么建议吗?

共有1个答案

慕容昊焜
2023-03-14

在资源管理器中,手动将所有泽西罐文件复制到WEB-INF / lib;当我遇到同样的问题时,我这样做了,这对我有用。

 类似资料:

相关问答

相关文章

相关阅读