Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException

java, servlets

Solution

I have been fighting the last 2 hours or so with an issue related to the javaee-api and javaee-web-api dependencies used for surefire plugin. As the guys at JBoss forum kindly posted a while ago, it appears as the whole JEE6 library was divided (as per Sun/Oracle decision) into an API (interfaces/stubs only) JAR and the providers.

How does that relate to this? If you have a problem with, say FacesContext class, you get an error like this:

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

If you take a look at the dependency tree you'll find a default API JAR in the compile classpath that is also getting in the way for runtime matters:

javax.faces:javax.faces-api:jar:2.1:provided

Adding an explicit exclusion for surefire plugin configuration will enforce the provider JAR dependencies usage at test time:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12</version>
    <configuration>
        <classpathDependencyExcludes>
            <!-- exclude code absent api -->
            <classpathDependencyExclude>javax.faces:javax.faces-api</classpathDependencyExclude>
        </classpathDependencyExcludes>
    </configuration>
</plugin>

Hope that helps, it did work for me.

Problem

I am planning to use Java servlets in my application. I included the following in my project's POM.xml file to load Java servlet 3.0 implementation jar. ``` <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.servlet</artifactId> <version>3.2-b05</version> </dependency> ``` The project compiles fine. However, when I run it, I get the following error: ``` java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException ``` I searched for it here and found some good answers. I figured out from them that this error happens when we include the JAR which contains only interfaces defined by servlet API and not the actual implementation. So, I checked that the glassfish jar I am using is just interfaces or it contains implementation too. I found that it is an implementation and not just interfaces. So now, I am wondering why I am getting this error at runtime. Anyone? UPDATE: Just now, I found out that it was a blatant error from my side (I was adding the jar to one project, while, was running an altogether different project!). I am sorry for this. Adding the glassfish servlet implementation DOES solve the issue. Thanks, Sandeep

Original source

Related problems