Java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter with Glassfish and JasperServer

Table of Contents 

Summary:

This article provides troubleshooting tips related to receiving a java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter error/exception.

You can encounter this exception when using Glassfish 2.1.1 and JasperReports Server v3.5.1

Symptoms:

Glassfish server is started but couldn't deploy JasperServer.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name \'sessionFactory\' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(Z)V Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.(Z)V at net.sf.cglib.core.DebuggingClassWriter.(DebuggingClassWriter.java:47) at net.sf.cglib.core.DefaultGeneratorStrategy.getClassWriter(DefaultGeneratorStrategy.java:30) at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24) at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216) at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145) at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117) at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108) at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104) at net.sf.cglib.proxy.Enhancer.(Enhancer.java:69) at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:107) at org.hibernate.proxy.pojo.cglib.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:43) at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162) at org.hibernate.tuple.entity.AbstractEntityTuplizer.(AbstractEntityTuplizer.java:135) at org.hibernate.tuple.entity.PojoEntityTuplizer.(PojoEntityTuplizer.java:55) at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.(EntityEntityModeToTuplizerMapping.java:56) at org.hibernate.tuple.entity.EntityMetamodel.(EntityMetamodel.java:269) at org.hibernate.persister.entity.AbstractEntityPersister.(AbstractEntityPersister.java:425) at org.hibernate.persister.entity.JoinedSubclassEntityPersister.(JoinedSubclassEntityPersister.java:91)

Causes:

Glassfish 2.1.1 use a new version of asm jar (3.x) and it conflicts with cglib-2.1_3.jar.

Resolutions:

Replace cglib-2.1_3.jar(shipped with JasperReports Server v3.5.1) by cglib-nodep-2.2.jar(shipped with JasperReports Server v3.7) and everything should run fine.

Also, but it has to be tested, you can even get rid of asm-1.5.3.jar and asm-attrs-1.5.3.jar since cglib-nodep-2.2.jar includes asm library.

Feedback
randomness