jersey NoClassDefFoundError: org/objectweb/asm/ClassVisitor exception
Asked Answered
U

2

23

First time I'm trying a WebService using jersey. The below code I got from some blog. I am getting following 500 error when I'm trying Java Web service using jersey client

javax.servlet.ServletException: Servlet.init() for servlet Jersey Root REST Service threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(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.servlet.WebAppResourceConfig.init(WebAppResourceConfig.java:102)
    com.sun.jersey.api.core.servlet.WebAppResourceConfig.<init>(WebAppResourceConfig.java:89)
    com.sun.jersey.api.core.servlet.WebAppResourceConfig.<init>(WebAppResourceConfig.java:74)
    com.sun.jersey.spi.container.servlet.WebComponent.getWebAppResourceConfig(WebComponent.java:672)
    com.sun.jersey.spi.container.servlet.ServletContainer.getDefaultResourceConfig(ServletContainer.java:415)
    com.sun.jersey.spi.container.servlet.ServletContainer.getDefaultResourceConfig(ServletContainer.java:582)
    com.sun.jersey.spi.container.servlet.WebServletConfig.getDefaultResourceConfig(WebServletConfig.java:87)
    com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:703)
    com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:678)
    com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:203)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
    com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
    javax.servlet.GenericServlet.init(GenericServlet.java:160)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    java.lang.Thread.run(Unknown Source)'

Below is my web.xml file

<?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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>RestFulWeb</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

   <servlet>
    <servlet-name>Jersey Root REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

 <init-param>
  <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
  <param-value>true</param-value>
 </init-param>
 <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey Root REST Service</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

</web-app>'

Here i tried adding the package also that didn't help:

Added only one jar file jersey-bundle-1.14.jar. The following is my Jersey server

package com.rest.server;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.rest.data.Hello;

// POJO, no interface no extends

// The class registers its methods for the HTTP GET request using the @GET annotation. 
// Using the @Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML. 

// The browser requests per default the HTML MIME type.

//Sets the path to base URL + /hello
@Path("/hello")
public class HelloWorldRest {

 @GET
 @Path("/{param}/")
 public String getMsg(@PathParam("param") String msg) {

  String output = "Jersey say : " + msg;

  return output;

 }
 @GET
 @Path("/world")
 public String getFixedMsg(String msg) {

  String output = "Jersey say : fixed path" + msg;

  return output;

 }
 // This method is called if TEXT_PLAIN is request
 @GET
 //@Path("helloworld")
 @Produces(MediaType.TEXT_PLAIN)
 public String sayPlainTextHello() {
  System.out.println("sayPlain");
  return "Hello Jersey";
 }

 // This method is called if XML is request
 @GET
 //@Path("helloworld")
 @Produces(MediaType.TEXT_XML)
 public String sayXMLHello() {
  System.out.println("sayXML");
  return "" + " Hello Jersey" + "";
 }

 // This method is called if HTML is request
 @GET
 //@Path("helloworld")
 @Produces(MediaType.TEXT_HTML)
 public String sayHtmlHello() {
  System.out.println("sayHTML");
  return "<html> " + "<title>" + "Hello Jersey" + "</title>"
    + "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
 }

 // This method is called if JSON is request
 @GET
 //@Path("helloworld")
 @Produces(MediaType.APPLICATION_JSON)
 public Hello sayJsonHello() {
  return new Hello("Hello", "Jersey");
 }

 @POST
 @Produces(MediaType.APPLICATION_JSON)
 public Hello createHello(Hello hello)
 {
  System.out.println("post");
  return hello;
 }

}'

currently I'm trying only with GET hitting the following url http://localhost:8080/RestFulWeb/hello, I am getting the 505 error.

DO i missed any jar files , but i didn't get any compile time error.

Uvular answered 24/7, 2013 at 7:12 Comment(4)
Have you added the required jar in your project ??Myotome
@BBdev: thanks, checked i missed jar's, previously added only one jar jersey-bundle-1.14.jar. now assed asm.jar and json.jar, its working fine now.Uvular
@BBDev, one doubt as a new bie here .. if i missed any jar it should give compile time error rite ?Uvular
If any jar dependent only in run time, it will throw exception in run time.Evangelical
E
42

This is caused by the missing of asm.jar,

Add this dependency

<dependency>

    <groupId>asm</groupId>

    <artifactId>asm</artifactId>

    <version>3.3.1</version>

</dependency>
Evangelical answered 24/7, 2013 at 7:24 Comment(2)
This works fine with com.sun.jersey:jersey-bundle:1.17Succumb
I have the asm jar, but its version 6.1, I am facing the same errorOvernight
C
0

While writing a webservice I was getting following error:

INFO: Scanning for root resource and provider classes in the packages:
  com.webservice.services
Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
    at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
    at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
    at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
    at com.webservice.StartWebService.startAttrService(StartWebService.java:32)
    at com.webservice.StartWebService.main(StartWebService.java:20)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.ClassVisitor
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 5 more

I included asm.jar in my java project and error gone. I was following steps from restful-web-services-first-application-mock-service-using-pure-java

Catechu answered 14/4, 2016 at 13:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.