在Apache Tomcat上部署WAR文件 - 不起作用

时间:2014-03-14 08:53:37

标签: java eclipse apache tomcat war

我使用Eclipse在Java中实现了一个API,并以 war 文件的形式将其导出。 它在我开发的系统上运行良好。

这是 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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Favorite-API</display-name>
  <servlet>
    <servlet-name>Favorite-API</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>favorite.api</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Favorite-API</servlet-name>
    <url-pattern>/rest-videos/*</url-pattern>
  </servlet-mapping>
</web-app>

现在我想在另一个系统上部署API。 因此,我按照here给出的步骤将war文件部署到另一台机器的Apache Tomcat服务器上。

但是在运行API时出现以下错误:

HTTP Status 500 -   
________________________________


type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: Servlet.init() for servlet Favorite-API threw exception
  org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
  org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
  org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
  java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  java.lang.Thread.run(Unknown Source)


root cause 

java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
  com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
  com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
  com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
  com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
  com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:696)
  com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:674)
  com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:205)
  com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
  com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
  javax.servlet.GenericServlet.init(GenericServlet.java:160)
  org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
  org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
  org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
  java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  java.lang.Thread.run(Unknown Source)


root cause 

java.lang.ClassNotFoundException: org.objectweb.asm.ClassVisitor
  org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
  org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
  com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
  com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
  com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
  com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
  com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:696)
  com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:674)
  com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:205)
  com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
  com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
  javax.servlet.GenericServlet.init(GenericServlet.java:160)
  org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
  org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
  org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
  org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
  java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  java.lang.Thread.run(Unknown Source)


note The full stack trace of the root cause is available in the Apache Tomcat/7.0.27 logs.

出了什么问题?请帮忙。

4 个答案:

答案 0 :(得分:3)

您的类路径中可能缺少某些依赖项。

java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor

假设您的开发tomcat具有此类/包,但不在您尝试部署战争的tomcat中。

答案 1 :(得分:1)

为servlet找不到类def意味着tomcat经常可用的某些servlet api现在由于某种原因而丢失。可能是tomcat的lib文件夹中的jar文件(可能是tomcat lib文件夹中的其他jar文件)已损坏或被删除。在我复制新的lib文件之前,两次都发生在我身上,错误的虚拟机工作,磁盘故障或基于maven的构建过程会将额外的api部署到lib文件夹并删除其中的内容。

答案 2 :(得分:1)

似乎你错过了$ TOMCAT_HOME / lib目录中的ObjectWeb ASM工件。

答案 3 :(得分:0)

听起来tomcat使用没有权限将WAR文件解压缩到相关目录中,这意味着应用程序本身无法找到所需的类。

确保Tomcat可以写入temp,work和webapps文件夹及其子目录。