简体   繁体   English

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

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

My Node.JS API (localhost) call a Jersey API on the Tomcat server (localhost) worked really well previously, but I don't know why it accidentally failed today.我的 Node.JS API (localhost) 调用了 Tomcat 服务器 (localhost) 上的 Jersey API 以前工作得很好,但我不知道为什么今天意外失败了。 I have checked that all files have not modified since last week.我检查了自上周以来所有文件都没有修改过。 Once I tried to GET http://localhost:8080/graybox/rest/analytic一旦我尝试获取http://localhost:8080/graybox/rest/analytic

It will fail and show these message in the eclipse console.它将失败并在 eclipse 控制台中显示这些消息。

SEVERE: Allocate exception for servlet [Jersey Web Application]
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:544)
    ...

I have surveyed a lot but I still can't find a way to solve my problem.我已经调查了很多,但我仍然找不到解决问题的方法。 The following is what I have done previously try to resolve this issue, which also attaches dev environment, web.xml and pom.xml.下面是我之前做的尝试解决这个问题,里面还附上了dev环境,web.xml和pom.xml。 Thanks.谢谢。

  1. Install maven (brew), m2eclipse (Eclipse install new software), m2e-wtp (Eclipse install new software) Eclipse install new software: Help -> Install New Software -> copy paste the url into "Work with" -> Choose all and Next and Finish m2eclipse m2e-wtp安装 maven (brew)、m2eclipse (Eclipse 安装新软件)、m2e-wtp (Eclipse 安装新软件) Eclipse 安装新软件:Help -> Install New Software -> 将 url 复制粘贴到“Work with”中 -> 全选并下一步并完成m2eclipse m2e-wtp
  2. Eclipse: Import -> Existing Maven project -> choose "graybox" project folder Eclipse:导入 -> 现有 Maven 项目 -> 选择“graybox”项目文件夹
  3. Rebuild Maven global index in Eclipse: Detail在 Eclipse 中重建 Maven 全局索引: 详细信息
  4. Add dependencies in Maven to make sure all jersey dependencies in the same version eg all 1.19 version jersey-server, jersey-bundle, jersey-core, jersey-json Reasons在 Maven 中添加依赖项以确保所有球衣依赖项都在同一版本中,例如所有 1.19 版本 jersey-server、jersey-bundle、jersey-core、jersey-json 原因
  5. Clean Maven dependencies清理 Maven 依赖项
    1. Project -> Clean -> Clean项目 -> 清洁 -> 清洁
    2. Right click project -> Maven -> Update Project右键项目 -> Maven -> 更新项目
    3. Right click project -> Run as -> 4 (or 5) Maven build -> Goals: clean install -> Apply -> Run Detail右键单击项目 -> 运行方式 -> 4(或 5)Maven 构建 -> 目标:全新安装 -> 应用 -> 运行细节
  6. If there are more than one Tomcat servers running, remove unrelated Tomcat servers, make sure choose the right one in runtime: Window -> Preferences -> Server -> Runtime Environments -> Remove all unrelated servers如果有多个Tomcat服务器在运行,删除不相关的Tomcat服务器,确保在运行时选择正确的:Window -> Preferences -> Server -> Runtime Environments -> Remove all unrelated servers
  7. Add server Tomcat Detail Before running the server, double-click the server -> Server Locations: Use Tomcat installation … Detail添加服务器Tomcat Detail在运行服务器之前,双击服务器-> Server Locations:使用Tomcat安装... Detail
  8. Right click project -> Properties -> Project facets -> Choose: Dynamic Web Module, Java, JavaScript, JAX-RS (REST Web Services) -> Runtimes -> Choose the right server -> Apply -> Apply and Choose右键单击项目 -> 属性 -> 项目构面 -> 选择:动态 Web 模块、Java、JavaScript、JAX-RS(REST Web 服务) -> 运行时 -> 选择正确的服务器 -> 应用 -> 应用并选择
  9. Start server -> Run project -> browser http://localhost:8080/ -> show welcome page of Tomcat启动服务器 -> 运行项目 -> 浏览器http://localhost:8080/ -> 显示 Tomcat 的欢迎页面

Environment环境

  • Mac os x 10.13.2, x86_64 Mac 操作系统 x 10.13.2、x86_64
  • Eclipse Oxygen.2 Release (4.7.2) Eclipse Oxygen.2 发布 (4.7.2)
  • Back-end后端
    • Java jdk1.8.0_151-b12 Java jdk1.8.0_151-b12
    • Tomcat 8.5雄猫 8.5
    • Maven 3.5.2 Default locale: en_AU, platform encoding: UTF-8 Maven 3.5.2 默认语言环境:en_AU,平台编码:UTF-8
    • Jersey 1.19泽西岛 1.19
    • Node 8.9.4节点 8.9.4
    • NPM 5.6.0新产品管理 5.6.0
    • Bower 1.8.2凉亭 1.8.2
    • Nodemon 1.14.11 Nodemon 1.14.11

This is web.xml这是 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
    <display-name>Graybox</display-name>
    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app>

This is pom.xml这是 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>graybox</groupId>
  <artifactId>graybox</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <finalName>graybox</finalName>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.6.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.3.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.0</version>
    </dependency>
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-server</artifactId>
      <version>1.19</version>
    </dependency>
    <dependency>
      <groupId>net.sourceforge.jexcelapi</groupId>
      <artifactId>jxl</artifactId>
      <version>2.6.10</version>
    </dependency>
    <dependency>
      <groupId>asm</groupId>
      <artifactId>asm</artifactId>
      <version>3.3.1</version>
    </dependency>
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-bundle</artifactId>
      <version>1.19</version>
    </dependency>
    <dependency>
      <groupId>org.json</groupId>
      <artifactId>json</artifactId>
      <version>20170516</version>
    </dependency>
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-core</artifactId>
      <version>1.19</version>
    </dependency>
    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-json</artifactId>
      <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.19</version>
    </dependency>
  </dependencies>
</project>

Due to accidentally shut down my Eclipse, it seems that the Java Build Path doesn't save Maven.由于不小心关闭了我的 Eclipse,Java Build Path 似乎没有保存 Maven。 It is the same as one of the answers answered by Adi和阿迪回答的其中一个答案一样

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

Right click your eclipse project Properties -> Deployment Assembly -> Add -> Java Build Path Entries -> Gradle Dependencies -> Finish.右键单击您的 eclipse 项目 Properties -> Deployment Assembly -> Add -> Java Build Path Entries -> Gradle Dependencies -> Finish。

暂无
暂无

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

相关问题 Jersey java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer - Jersey 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 将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 春季启动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