java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/MessagingException

absent code attribute in method that is not native or abstract in class file javax/xml/ws/service
java lang classformaterror jvmcfre074 no code attribute specified

I have a maven dependency for javaee Bibliothek.

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>6.0</version>
    <scope>provided</scope>
</dependency>

I get the error in Eclipse in some classes.

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/MessagingException

I added javax.mail dependency.

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.5</version>
</dependency>

It did not not work. Any Idea??

It doesn't work because classes from javax/javaee-api/provided dependency are specially constructed. They are not usable runtime because implementation of methods is missing.

Simply adding classes from javax.mail/mail/1.4.5 dependency to the classpath does not help, because classes from javax/javaee-api/provided are already there. Having javax.mail/mail/1.4.5 dependecy alone solves your problem, but most likely you also need other classes from javax/javaee-api/provided.

What you can do is to get rid of javax/javaee-api/provided dependency and get these classes for example from the dependencies provided by target application server. You can use for example following:

   <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-6.0</artifactId>
        <version>1.0.0.Final</version>
        <type>pom</type>
        <scope>provided</scope>
     </dependency>

Because scope is provided, it does not affect the artifact to be built. That's why you can use this one also with other application servers than JBoss. It is same API as in your original dependency, but it contains normal classes.

ClassFormatError: Absent Code attribute in method that is not native , If you need classes suitable for running against, run against a Java EE application server. Also, the Absent Code attribute in method that is not native or abstract in class file javax/servlet/http/ <dependency> <groupId>javax.mail</​groupId> <artifactId>mail</artifactId> Exception in constructor: testDoExecute (​java.lang. I have the same problem as you and found out that change from servlet-api to javax.servlet.api will fix the problem. Hope this help. Please note that, I am using Juno Eclipse, Tomcat 7, Dynamic Web Module 3.0, and JDK 1.7.

in my case, only use the library:

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4</version>
</dependency>

Run with JDK 6 and Tomcat without problems

java.lang.ClassFormatError : Absent Code attribute in method that is , ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/GenerationType at java.lang. java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file “name of class” 2 “Absent Code attribute in method that is not native or abstract in class” exception when starting a project in Netbeans 7.2

Weird but the following order works for me,

    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>

The reverse won't work.

[java] java.lang.ClassFormatError: Absent Code attribute in method , [java] java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/jsp/PageContext #328. 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

If you add them to your pom in this order: javax.mail javaee-web-api it is pretty logical that it will work, because the runtime finds the necessary class first (with the proper implementation) from javax.mail, ignoring any similar class (without implementation) from javaee-web-api.

Email: java.lang.ClassFormatError (Java API forum at Coderanch), run: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/Address at java.lang.ClassLoader. throws MessagingException, AddressException. {. for ( int i = 0 ; i<=  Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/jms/JMSException at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

In my case i use following order. Work very well with JDK6.

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4</version>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>javaee</groupId>
    <artifactId>javaee-api</artifactId>
    <version>5</version>
    <scope>provided</scope>
</dependency>

Absent Code attribute in method that is not native or abstract, lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/security/jacc/PolicyContext; at java. [java] java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/jsp/PageContext #328

Maven + JUnit + ClassFormatError: Absent Code attribute in method , ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/Session at java.lang.ClassLoader. I cannot reproduce the issue in today's build. I did a change in facelets classloading yesterday which might affect this issue. Anyway looks like caused by the "stub" classes from javaee-api.jar which somehow got to the classpath.

Resolving java.lang.ClassFormatError: Absent Code attribute in , java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/validation/Validation. at java.lang. java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/Session This happens if your code compiles against incomplete classes, like the JavaEE6 Api and your Unit tests try to access code thats not there. JUnit will simply fail and mark the test as error, printing something like this

generating the email - JavaMail, java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/MessagingException.

Comments
  • I added more instructions to answer.
  • I always put the javaee-api dependency LAST in the pom.xml, with the implementation jars before it, that fixes it too
  • I need also the other libraries from javaee
  • This Actually works. @prayag upd Can you please post little more details about how it works exactly.