web.xml出问题了吗? 我不在这里使用maven,而是使用eclipse,tomcat 8.5和 jersey 2.27
创建了动态Web应用程序请首先查看我的web.xml?我在web.xml中没有使用正确的servlet类和init-param吗?我的问题不只是异常,我不确定web.xml
导致以下错误:
http状态:500
javax.servlet.ServletException:Servlet [jersey-servlet]的Servlet.init()抛出异常。
java.lang.NoClassDefFoundError:无法初始化org.glassfish.jersey.internal.inject.Providers类
下面是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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"
id="WebApp_ID" version="3.1">
<display-name>RestWebService</display-name>
<servlet>
<servlet-name>jersey-servlet</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.swapnil.webservice</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
我的java类:
package com.swapnil.webservice;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
@Path("*/helloWorld")
public class HelloRestService {
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("name")
public String getGreeting(@Context HttpHeaders httpHeaders, @PathParam("name") String name) {
String greeting = "Hello" + name;
return greeting;
}
}