0

I implemented an API in Java using Eclipse and exported it in the form of a war file. It is working fine on the system I developed it on.

This is the 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>

Now I want to deploy the API on another system. Hence I took the war file and deployed it on the Apache Tomcat server of the other machine, following the steps given here.

But on running the API I am getting the following error:

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.

What is going wrong? Any help please.

Community
  • 1
  • 1
Abhishek
  • 125
  • 2
  • 17
  • Some libraries seem to be missing. Check which library contains `org.objectweb.asm.ClassVisitor` and put it into your `WEB-INF/lib` folder or check whether you need `org.objectweb.asm.ClassVisitor` at all, i.e. does your custom code directly depend on that class or the framework/library that contains it? – Thomas Mar 14 '14 at 08:57
  • 1
    Classic mistake: "It works on my machine!" – duffymo Mar 14 '14 at 08:59
  • @Thomas All needed libraries are there in the WEB-INF/lib folder. – Abhishek Mar 14 '14 at 09:05
  • 1
    Well, it doesn't seem so. It might be a transitive dependency that's missing. A `ClassNotFoundException` tells you that the classes are not found by the container and I'd assume Tomcat contains all the libraries it needs for application without special requirements. – Thomas Mar 14 '14 at 09:10
  • Might also be a version problem; it might be that the right library is deployed (asm) but that the version deployed does not yet contain said class. In any case let go of "I did everything correct", no you did not because a required class is missing. Figure out which jar contains that class and you'll figure out what is wrong. – Gimby Mar 14 '14 at 09:13
  • @Gimby Could you elaborate on the version problem? – Abhishek Mar 14 '14 at 09:39
  • Not really. I can try to explain it differently: "the version you're deploying may be older than the version required for other dependencies". – Gimby Mar 14 '14 at 10:16

4 Answers4

3

You might have some dependencies missing in your class path.

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

Assume your development tomcat has this class/package but not in the tomcat which you are trying to deploy the war.

sura2k
  • 7,365
  • 13
  • 61
  • 80
1

class def not found for servlet means something servlet api that is regularly available to tomcat is now missing for some reason. Possibly the jar file in tomcat's lib folder (maybe other jar files in the tomcat lib folder) have become corrupted or removed. Both have happened to me at times, bad virtual machine to work on, failed disk, or a maven based build process that would deploy additional api to the lib folder and delete things in there before copying the new lib files.

Stathis Andronikos
  • 1,259
  • 2
  • 25
  • 44
1

Seems you are missing the ObjectWeb ASM artifact in your $TOMCAT_HOME/lib directory.

tmarwen
  • 15,750
  • 5
  • 43
  • 62
0

It sounds like the tomcat use does not have permissions to unpack the WAR file into relevant directories, which means the application itself cannot find required classes.

Ensure that Tomcat can write to the temp, work and webapps folder, and their subdirectories.

Garreth McDaid
  • 2,427
  • 22
  • 34