web-dev-qa-db-fra.com

jersey NoClassDefFoundError: exception org/objectweb/asm/ClassVisitor

La première fois que j'essaye un WebService en utilisant un maillot. Le code ci-dessous, je viens d'un blog . J'obtiens le message d'erreur suivant lorsque j'essaie le service Web Java avec un client jersey

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)'

Ci-dessous mon fichier 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_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>'

Ici, j'ai essayé d'ajouter le paquet qui n'a pas aidé:

Ajout d'un seul fichier jar jersey-bundle-1.14.jar. Ce qui suit est mon serveur Jersey

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;
 }

}'

actuellement, j'essaie uniquement avec GET en tapant l'url http://localhost:8080/RestFulWeb/hello suivant, je reçois l'erreur 505. 

Est-ce que j'ai raté des fichiers jar, mais je n'ai pas eu d'erreur de compilation?.

23
user2502314

Ceci est causé par l'absence de asm.jar,

Ajouter cette dépendance 

<dependency>

    <groupId>asm</groupId>

    <artifactId>asm</artifactId>

    <version>3.3.1</version>

</dependency>
40
Veera

Lors de l'écriture d'un service Web, l'erreur suivante était générée:

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

J'ai inclus asm.jar dans mon projet Java et l'erreur est partie . Je suivais les étapes de reposant-services-Web-première-application-fausse-service-utilisant-pur-Java

0
Jyoti Prakash