java.lang.ClassFormatError : Absent Code attribute in method that is not native or abstract in class file …
Problem
A very strange and rare problem, happened in JPA or Hibernate development.
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is
not native or abstract in class file javax/persistence/GenerationType
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknow
Solution
This is always caused by the javaee.jar which is located at Java.net. Many developers like to grab the javaee.jar with the following Maven coordinate :
<repositories>
<repository>
<id>Java.Net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
<dependencies>
<!-- Javaee API -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>
</dependencies>
But, the javaee.jar from java.net is not contains any method bodies, but the APIs name only. Which is not suitable to use for running or deploying along with your application.
The good practice is always get the original full version of javaee.jar file from the http://java.sun.com/javaee/. Just download and install the J2EE SDK, and the javaee.jar can be found in the “\J2EE_SDK_FOLDER\lib” folder. Include it into your local Maven repository or poject classpath will get rid of the above error message.
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/webapp/FacesServlet
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2854)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1159)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1647)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:108)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:58)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:297)
at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1078)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:261)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4612)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
I am having this issue i am not using maven… please help me hwo to fix this problem
INFO: keepstate options resolved to true, saving appId 111542901784248320 for application GYM.
INFO: EclipseLink, version: Eclipse Persistence Services – 2.7.11.payara-p1
INFO: Portable JNDI names for EJB User: [java:global/GYM/User!ejb.UserLocal, java:global/GYM/User]
INFO: Portable JNDI names for EJB SuperAdmin: [java:global/GYM/SuperAdmin, java:global/GYM/SuperAdmin!ejb.SuperAdminLocal]
INFO: Portable JNDI names for EJB Admin: [java:global/GYM/Admin!ejb.AdminLocal, java:global/GYM/Admin]
INFO: Clustered CDI Event bus initialized
INFO: Initializing Soteria 1.1-b01.payara-p5 for context ‘/GYM’
INFO: Initializing Mojarra |version.string| for context ‘/GYM’
INFO: Loading application [GYM] at [/GYM]
INFO: GYM was successfully deployed in 1,598 milliseconds.
INFO: keepstate options resolved to true, saving appId 111542901784248320 for application GYM.
INFO: EclipseLink, version: Eclipse Persistence Services – 2.7.11.payara-p1
INFO: Portable JNDI names for EJB Admin: [java:global/GYM/Admin!ejb.AdminLocal, java:global/GYM/Admin]
INFO: Portable JNDI names for EJB User: [java:global/GYM/User!ejb.UserLocal, java:global/GYM/User]
INFO: Portable JNDI names for EJB SuperAdmin: [java:global/GYM/SuperAdmin, java:global/GYM/SuperAdmin!ejb.SuperAdminLocal]
INFO: Clustered CDI Event bus initialized
INFO: Initializing Soteria 1.1-b01.payara-p5 for context ‘/GYM’
INFO: Initializing Mojarra |version.string| for context ‘/GYM’
INFO: Loading application [GYM] at [/GYM]
INFO: GYM was successfully deployed in 1,570 milliseconds.
INFO: keepstate options resolved to true, saving appId 111542901784248320 for application GYM.
INFO: EclipseLink, version: Eclipse Persistence Services – 2.7.11.payara-p1
INFO: Portable JNDI names for EJB SuperAdmin: [java:global/GYM/SuperAdmin, java:global/GYM/SuperAdmin!ejb.SuperAdminLocal]
INFO: Portable JNDI names for EJB Admin: [java:global/GYM/Admin!ejb.AdminLocal, java:global/GYM/Admin]
INFO: Portable JNDI names for EJB User: [java:global/GYM/User!ejb.UserLocal, java:global/GYM/User]
INFO: Clustered CDI Event bus initialized
INFO: Initializing Soteria 1.1-b01.payara-p5 for context ‘/GYM’
INFO: Initializing Mojarra |version.string| for context ‘/GYM’
INFO: Loading application [GYM] at [/GYM]
INFO: GYM was successfully deployed in 1,283 milliseconds.
INFO: keepstate options resolved to true, saving appId 111542901784248320 for application GYM.
SEVERE: Absent Code attribute in method that is not native or abstract in class file servlet/test
SEVERE: Absent Code attribute in method that is not native or abstract in class file servlet/test
please solve this error and help me
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.filter.CharacterEncodingFilter]: Factory method ‘characterEncodingFilter’ threw exception; nested exception is java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
… 42 common frames omitted
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException
Can you help with this error ?
thank you, again again.
It’s working fine now. Thank You.
Getting exception while creating client. jersey-core-1.13.jar and jersey-client-1.13.jar are included as Maven dependency.
Client c = Client.create ();
gives:
Exception in thread “main” java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ws/rs/core/MediaType
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
Please help!
Hi
Anamika Mishra’s approach solves problems with applications installed on a Java EE server, but it does not solve the problem for tests executed during the Maven lifecycle, because dependencies in scope provided are available at the test runtime.
For those experiencing this problem during tests there is another solution: https://community.jboss.org/wiki/WhatsTheCauseOfThisExceptionJavalangClassFormatErrorAbsentCode
I favour this over having the full javaee.jar as part of my final application archive (war/ear)
Seriously? That really makes unit testing my ‘POJOs’ really hard.
I have got the folow error:
Exception in thread “main” java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ejb/EJBException
I’ve added the following in the pom.xml file and its work. I hope to be helpful.
javax.ejb
ejb-api
provided
javaee
javaee-api
provided
I’d like to know how to see if my JAR is an API only. It has .class files but is there a way to really tell? Do you have the filesize for the 2 different versions?
2 years after leaving my comment here, I still don’t know how to fix the error, because I never got a response to my question. Sigh.
please i need help in developing standalone application using EJB.
first i thank all who have been contributing in java.i am new to EJB.
my problem is :i tried to build remote application using Ejb ,
1. i build entity bean from datebase
2. i tried to build session bean from entity class for remote AP.
then error=”EJB Remote Interface depends on JPA AEntity classes. JPA Entities are inaccessible if they are located in mode.” i used netbean 7.2.1.
as i was making a research over a week ,i stormble over this solution
1 .that i should build class library
2. create entity bean in the class library
3.add the class library to the already created ejeModule
4.create persistence Unit
5.create session bean for entity class in ejbModule .
Great i used that to create my Remote application .
BUT:when i tried to build my ejeModule i keep on seen this malignant error
=”An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/PersistenceException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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:423)
at
at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getField(PrivilegedAccessHelper.java:216)
at org.eclipse.persistence.internal.helper.Helper.getField(Helper.java:934)
at org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor.initializeAttributes(InstanceVariableAttributeAccessor.java:100)its(PersistenceUnitReader.java:168)
at org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnitReader.
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1106)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.tools.javac.main.Main.compile(Main.java:417)
at com.sun.tools.javac.main.Main.compile(Main.java:331)
at com.sun.tools.javac.main.Main.compile(Main.java:322)
at com.sun.tools.javac.Main.compile(Main.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
C:\Users\Administrator\Documents\NetBeansProjects\serva\nbproject\build-impl.xml:849: The following error occurred while executing this line:
C:\Users\Administrator\Documents\NetBeansProjects\serva\nbproject\build-impl.xml:258: Compile failed; see the compiler error output for details.
please i need help.i have spend over a week and some days trying to get rid of this ,please my Java gurus give me a step by step solution in this ,i am new to EJE .
Hi,
My name is Meursaul, first excuse me for my English because it is not good.
Thank you mkyong and thank you all man who contribute to this tutoriel, it is helpfull.
I try to execute the example where you used spring+hibernate+struts and maven and i have this error:
————————————————————————
[ERROR] Failed to execute goal org.codehaus.mojo:tomcat-maven-plugin:1.1:run (default-cli) on project aaaa: Execution default-cli of goal org.codehaus.mojo:tomcat-maven-plugin:1.1:run failed: An API incompatibility was encountered while executing org.codehaus.mojo:tomcat-maven-plugin:1.1:run: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/http/HttpServlet
[ERROR] —————————————————–
[ERROR] realm = plugin>org.codehaus.mojo:tomcat-maven-plugin:1.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/boussad/.m2/repository/org/codehaus/mojo/tomcat-maven-plugin/1.1/tomcat-maven-plugin-1.1.jar
[ERROR] urls[1] = file:/C:/Users/boussad/.m2/repository/org/apache/maven/maven-archiver/2.2/maven-archiver-2.2.jar
[ERROR] urls[2] = file:/C:/Users/boussad/.m2/repository/org/codehaus/plexus/plexus-archiver/1.0-alpha-7/plexus-archiver-1.0-alpha-7.jar
[ERROR] urls[3] = file:/C:/Users/boussad/.m2/repository/org/codehaus/plexus/plexus-utils/1.0.4/plexus-utils-1.0.4.jar
[ERROR] urls[4] = file:/C:/Users/boussad/.m2/repository/commons-codec/commons-codec/1.3/commons-codec-1.3.jar
[ERROR] urls[5] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/catalina/6.0.29/catalina-6.0.29.jar
[ERROR] urls[6] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/juli/6.0.29/juli-6.0.29.jar
[ERROR] urls[7] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/annotations-api/6.0.29/annotations-api-6.0.29.jar
[ERROR] urls[8] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/catalina-ha/6.0.29/catalina-ha-6.0.29.jar
[ERROR] urls[9] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/tribes/6.0.29/tribes-6.0.29.jar
[ERROR] urls[10] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/el-api/6.0.29/el-api-6.0.29.jar
[ERROR] urls[11] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/jasper/6.0.29/jasper-6.0.29.jar
[ERROR] urls[12] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/jasper-el/6.0.29/jasper-el-6.0.29.jar
[ERROR] urls[13] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/jasper-jdt/6.0.29/jasper-jdt-6.0.29.jar
[ERROR] urls[14] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/jsp-api/6.0.29/jsp-api-6.0.29.jar
[ERROR] urls[15] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/servlet-api/6.0.29/servlet-api-6.0.29.jar
[ERROR] urls[16] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/coyote/6.0.29/coyote-6.0.29.jar
[ERROR] urls[17] = file:/C:/Users/boussad/.m2/repository/org/apache/tomcat/dbcp/6.0.29/dbcp-6.0.29.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] —————————————————–
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException
Is there someone who can help me ? Thank you 🙂
Thanks mkyong that surely explains the issue in details. Another way of solving this could be using the maven scope as provided i.e.
. This ensures that the api only jar is used only for compilation and not at run time. Place the implementation jar in the server lib.
Sorry but i dont know how to add above dependencies in project..
Your directions are very helpfull.
Many thanks for that.
ps.
java.net make big mess whit his libraires – they are in NetBeans IDE.
I was curious if you ever considered changing the page layout of your site?
Its very well written; I love what youve got to say.
But maybe you could a little more in the way of content so people
could connect with it better. Youve got an awful lot of
text for only having one or two pictures. Maybe you could
space it out better?