Error:Java.Lang.Nosuchmethoderror: Org.Objectweb.Asm.Classwriter.<Init>(I)V

Error : java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.init(I)V

You have an incompatibility between the version of ASM required by Hibernate (asm-1.5.3.jar) and the one required by Spring. But, actually, I wonder why you have asm-2.2.3.jar on your classpath (ASM is bundled in spring.jar and spring-core.jar to avoid such problems AFAIK). See HHH-2222.

Hibernate: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(Z)V

You can remove the asm dependency:

<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3.1</version>
<scope>compile</scope>
</dependency>

from your pom.

Hibernate will pull it into your project transitively (at the correct version) so there is no need to include it in your pom. Adding un-necessary dependencies will often lead to incorrect versions of required jars being included.

Exception java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter on Viewing Jasper Report

Note that you have two different versions of ASM listed. This is a very common problem with that library because so many other libraries use it under the hood and because Java's classpath mechanism doesn't allow for using different versions of the same library. (This happens all the time between Groovy and Hibernate.) So when you set up your classpath, one library wants version 2.2.3, and one wants 3.1. When looking up classes, though, the first one on the classpath wins. In your case, Groovy is trying to call a constructor on ClassWriter that doesn't exist in whichever version won (2.2.3, if you listed them in the actual classpath order). When you have this situation, where different versions are being demanded, all you can do is pick a version and cross your fingers. Try it out to see if it works everywhere you need it to. Most likely, everything will be fine if you use the newer ASM version (3.1). That's been my experience, anyway. If you can't find a version that works for everything, you might have a big problem on your hands.

Spring + Hibernate on Google Apps Engine error (java.lang.NoClassDefFoundError: org/objectweb/asm/ClassWriter)

A java.lang.NoSuchMethodError (in your case (java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V)) mean that the class (ClassWriter) exists, but the method (in your case: constructor with boolean argument) not.

This kind of error often occurs if there are incompatible libaries: One lib requires version x of lib B, but you have version y of lib B. And this two versions are not compatible.

If your project was running with Netbeans, but not with Eclipse then I guess you have modified the libs while moving the projects from one IDE to the other.

In your case the Class DebuggingClassWriter from cgilib-2.2.jar invoke in its constructor the constructor (with one boolean parameter) of its superclass ClassWriter from asm.jar (unfortunately you have not specified the version of the asm.jar you use).
But I can tell you that for example asm-3.1.jar contains the constructor you need.

BTW: I use cglib-nodep-2.2.jar together with asm-3.1.jar, and it works

SEVERE: Initial SessionFactory creation failed.java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.init(Z)V

You have asm version that is incompatible with your Hibernate version. One way to check for compatible versions is to take a look to the maven dependencies, here for example for hibernate-core. It is usable way even if you do not maven builds.

One working combination for example is:

  • Hibernate 3.6.10,
  • cglib 2.2
  • asm 3.1.

If you need answer that is more suited for you, you have to share information about which libraries are included at the moment.

Error: java.lang.NoSuchMethodError: org/springframework/asm/ClassVisitor.init(I)V

Solution to your Question

  1. It seems there is a JAR conflict while managing your dependencies.
  2. In Spring 4.2.0, the ClassVisitor class have been included in Spring-core-4.2.0.RELEASE.jar, Please find the below image. Hence there is no need to include spring-asm-3.1.3.RELEASE.jar which I have found in your dependencies.
    ClassVisitor
  3. It is always recommended to use Bill of Materials when you are using Spring 3.2.X and above versions.
  4. Please remove the CGLIB Proxy from dependency, as it is no longer needed when you are using Spring 3.2.X version and above. Please refer the spring-framework documentation for this.
  5. Finally your POM should be like this below. Humbly requesting you to ignore the hibernate and slf4j dependencies.

                                                <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.springframework.samples</groupId>
    <artifactId>simpleSpring</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>

    <!-- Generic properties -->
    <java.version>1.8</java.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <!-- Spring -->
    <spring-framework.version>4.2.0.RELEASE</spring-framework.version>

    <!-- Hibernate / JPA -->
    <hibernate.version>4.2.1.Final</hibernate.version>

    <!-- Logging -->
    <logback.version>1.0.13</logback.version>
    <slf4j.version>1.7.5</slf4j.version>

    <!-- Test -->
    <junit.version>4.11</junit.version>

    </properties>
    <dependencies>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aspects</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-expression</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-instrument</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-instrument-tomcat</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jms</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-messaging</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-oxm</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc-portlet</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-websocket</artifactId>
    <version>4.2.0.RELEASE</version>
    </dependency>

    <!-- Spring and Transactions -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring-framework.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>${spring-framework.version}</version>
    </dependency>

    <!-- Logging with SLF4J & LogBack -->
    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
    <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>${logback.version}</version>
    <scope>runtime</scope>
    </dependency>

    <!-- Hibernate -->
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>${hibernate.version}</version>
    </dependency>

    <!-- Test Artifacts -->
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>${spring-framework.version}</version>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>${junit.version}</version>
    <scope>test</scope>
    </dependency>

    </dependencies>
    </project>


Related Topics



Leave a reply



Submit