我遇到了一個問題,試圖使用maven將servlet部署到Tomcat; 我一直在閱讀關於這個問題的其他帖子,但仍然不能成功的答案/建議。Jersey servlet異常tomcat球衣
我得到這個例外,無論我嘗試:
javax.servlet.ServletException:Servlet.init()進行的servlet新澤西Web應用程序拋出異常 org.apache.catalina.authenticator .AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) org.apache.coyote.http11.AbstractHttp11Processor.pro (AbstractHttp11Processor.java:1091) org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:673) org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1500) org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1456) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) java.util.concurrent.ThreadPoolExecutor $ Worker .run(ThreadPoolExecutor.java:615) org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745) 根本原因 com.sun.jersey.api.container.ContainerException:ResourceConfig實例不包含任何根資源類。 com.sun.jersey.server.impl.application.RootResourceUriRules。(RootResourceUriRules.java:99) com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1359) com.sun。 jersey.server.impl.application.WebApplicationImpl.access $ 700(WebApplicationImpl.java:180) com.sun.jersey.server.impl.application.WebApplicationImpl $ 13.f(WebApplicationImpl.java:799) com.sun.jersey。 server.impl.application.WebApplicationImpl $ 13.f(WebApplicationImpl.java:795) com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193) com.sun.jersey.server.impl.application .WebApplicationImpl.initiate(WebApplicationImpl.java:795) com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790) com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:509) com.sun.jersey.spi.container.servlet.ServletContainer $ InternalWebComponent.initiate(ServletContainer.java:339) com .sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207) com.sun.jersey .spi.container.servlet.ServletContainer.init(ServletContainer.java:394) com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577) javax.servlet.GenericServlet.init(GenericServlet .java:158) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorR eportValve.invoke(ErrorReportValve.java:79) org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) 組織.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:673) org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor .doRun(NioEndpoint。java:1500) org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1456) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) java.util.concurrent .ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615) org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) java.lang.Thread.run(Thread.java:745 )
這是我的web.xml文件:
<servlet>
<servlet-name>Jersey Web Application</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>com.rest.example
</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>
而且我的pom.xml
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>asm.jar</artifactId>
<version>20041228.180559</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>jersey-bundle.jar</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>jersey-server.jar</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>jersey-core.jar</artifactId>
<version>1.8</version>
<type>pom.lastUpdated</type>
</dependency>
的sum.java文件
package com.rest.example;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
public class sum {
@Path("/hello")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayHello()
{
return "Hello World";
}
}
以防萬一:
我試圖清理和重新構建它,但仍沒有改變; 我錯過了什麼?謝謝。
謝謝!它正在工作 – ohadsas