【发布时间】:2017-02-22 02:26:11
【问题描述】:
我正在尝试使用 Jersey 在 Eclipse 上创建一个 RESTful 服务。
当我尝试在 Eclipse 中的 localhost 中运行时,我反复收到以下错误。
SEVERE: Servlet [Jersey Web Application] in web application [/TestPrject] threw load() exception
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
我的 web.xml 看起来像这样:
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
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>TestPrject</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey Web Application</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.eviac.blog.MyTestSvc</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
我在 WEB-INF/lib 下也有所有 Jersey 2.0 jar。我正在使用 JDK 1.7.0_79 运行 Apache Tomcat 8.0。
Service入口使用的Class如下:
@Path("/")
public class MyTestSvc {
@GET
@Path("/callService")
@Produces({ "text/plain" })
public String userName() {
return "hello";
}
}
有什么我可能会出错的想法吗?
【问题讨论】:
标签: java eclipse rest jersey tomcat8