[英]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.
谢谢。
Environment环境
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.