我遵循这个http://www.ibm.com/developerworks/library/wa-aj-tomcat/中的确切步骤,并且我正确地包含了所有的罐子(我相信)。而且我仍然收到如下错误:
Jun 24, 2013 7:16:21 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Jun 24, 2013 7:16:21 PM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
com.sun.jersey.api.container.ContainerException: No WebApplication provider is present
at com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:69)
at com.sun.jersey.spi.container.servlet.ServletContainer.create(ServletContainer.java:360)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.create(ServletContainer.java:275)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:585)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:213)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:342)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:516)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5407)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Jun 24, 2013 7:16:21 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /Jersey threw load() exception
com.sun.jersey.api.container.ContainerException: No WebApplication provider is present
at com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:69)
at com.sun.jersey.spi.container.servlet.ServletContainer.create(ServletContainer.java:360)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.create(ServletContainer.java:275)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:585)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:213)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:342)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:516)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5407)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
我只是做了第一步,显示你好。我的 web.xml 和 java 文件如下:
package sample.hello.resources;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/hello")
public class HelloResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayHello() {
return "Hello Jersey";
}
}
web.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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>Jersey</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>sample.hello.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>
我已经在谷歌上搜索了一段时间,我找不到一个好的解决方案。顺便说一句,我的 jar 文件列表是:activation.jar asm-3.1.jar com.sun.jersey.jersey-server-1.4.0.jar jaxb-api-2.2.5.jar jaxb-impl-2.2_1.jar jersey- client.jar jersey-core.jar jersey-json-1.7.jar jersey-spring-1.11-b02.jar jsr311-api.1.1.1.jar stax-api.jar wstx-asl.jar
这些罐子在网络上被推荐。我将它们直接复制到 WEB-INF/lib 文件夹中。我担心的一件事是路径问题,之前有人告诉我我应该通过右键单击类项目->构建路径来添加一些 jars,然后添加 jars。我也试过了,不是好消息。我正在运行Tomcat7.0。网络也运行到错误报告页面。请帮助!
我尝试了两个本地主机链接:8080/Jersey/WEB-INF/web.xml & 8080/Jersey/rest/hello。都失败了!
提前致谢。