简体   繁体   English

方法中的Absent Code属性在类文件javax / servlet / ServletException中不是本机的或抽象的

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

I am planning to use Java servlets in my application. 我打算在我的应用程序中使用Java servlet。 I included the following in my project's POM.xml file to load Java servlet 3.0 implementation jar. 我在我的项目的POM.xml文件中包含以下内容以加载Java servlet 3.0实现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. 我从他们中发现,当我们包含仅包含由servlet API定义的接口而不是实际实现的JAR时,会发生此错误。 So, I checked that the glassfish jar I am using is just interfaces or it contains implementation too. 所以,我检查了我正在使用的glassfish jar只是接口或它也包含实现。 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!). 刚才,我发现这是我身边一个明显的错误(我正在将jar添加到一个项目中,而正在运行一个完全不同的项目!)。 I am sorry for this. 对不起,我很抱歉。 Adding the glassfish servlet implementation DOES solve the issue. 添加glassfish servlet实现可以解决问题。

Thanks, Sandeep 谢谢,Sandeep

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. 我在过去2个小时左右的时间里一直在与一个与用于surefire插件的javaee-api和javaee-web-api依赖项相关的问题进行斗争。 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. 正如JBoss论坛上的人们刚才发布的那样,看来整个JEE6库被划分(根据Sun / Oracle的决定)分为API(仅限接口/存根)JAR和提供者。

How does that relate to this? 这与此有何关系? If you have a problem with, say FacesContext class , you get an error like this: 如果您遇到问题,比如FacesContext类 ,则会出现如下错误:

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: 如果你看一下依赖树,你会在编译类路径中找到一个默认的API JAR,它也会影响运行时的问题:

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: 为surefire插件配置添加显式排除将在测试时强制使用提供程序JAR依赖项:

<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. 希望有所帮助,它确实对我有用。

I traded to glassfish-embedded-all and resolved this. 我交易到glassfish-embedded-all并解决了这个问题。

    <dependency>
        <groupId>org.glassfish.main.extras</groupId>
        <artifactId>glassfish-embedded-all</artifactId>
        <version>3.1.2.2</version>
        <scope>provided</scope>
    </dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2.2</version>
<scope>provided</scope>

It worked for me. 它对我有用。 Thanks. 谢谢。 But order in pom.xml also matters as for me 但是pom.xml中的顺序对我来说也很重要

 <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.main.extras</groupId>
        <artifactId>glassfish-embedded-all</artifactId>
        <version>3.1.2.2</version>
        <scope>test</scope>
    </dependency>

Above order Does not Work 以上顺序不起作用

<dependency>
        <groupId>org.glassfish.main.extras</groupId>
        <artifactId>glassfish-embedded-all</artifactId>
        <version>3.1.2.2</version>
        <scope>test</scope>
    </dependency>
 <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>

Above Order Works 以上订单工程

I faced same error using Jersey specifically when I run my tests (JUnit + Mockito). 当我运行我的测试(JUnit + Mockito)时,我特别使用了Jersey。 What works for me was adding the code below to my pom.xml file. 对我有用的是将下面的代码添加到我的pom.xml文件中。

<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-test-framework</artifactId>
   <version>1.1.5.1</version>
   <scope>test</scope>
</dependency>

Note: I'm using Jersey 1.17 注意:我正在使用Jersey 1.17

I recently encountered this same error and, thanks to this question and the above answers - especially leandro.freitos - I was able to resolve it using 我最近遇到了同样的错误,感谢这个问题和上面的答案 - 特别是leandro.freitos - 我能够使用它来解决它

 <dependency>
    <groupId>org.glassfish.main.extras</groupId>
    <artifactId>glassfish-embedded-all</artifactId>
    <version>3.1.2.2</version>
    <scope>provided</scope>
</dependency>

Turns out mine had to do with javax.servlet 原来我的javax.servlet也有

I had a similar case to the one josdem had (same error, also while running JUnit with Mockito), but without Jersey. 我有一个类似于josdem的情况(同样的错误,同时运行JUnit与Mockito),但没有泽西岛。 So here's a Jersey-independent solution that worked for me: 所以这是一个独立的泽西岛解决方案,对我有用:

    <dependency> 
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-servlet_3.0_spec</artifactId>
        <version>1.0</version>
        <scope>test</scope>
    </dependency>

Same problem here. 同样的问题在这里 Though it turned out for me to be the order in which I was declaring dependencies. 虽然我发现这是我声明依赖关系的顺序。 The glassfish embedded dependency needs to be declared ahead of the provided javaee-web-api dependency. 需要在提供的javaee-web-api依赖项之前声明glassfish嵌入式依赖项。

    <dependency>
        <groupId>org.glassfish.extras</groupId>
        <artifactId>glassfish-embedded-all</artifactId>
        <version>3.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>

I'm not sure why the class path gets muddled when the glassfish embedded is placed after the javaee-web-api in tests. 当测试中的javaee-web-api之后放置glassfish嵌入时,我不确定为什么类路径会变得混乱。 I suppose the JVM tries to resolve the javax classes in the provided first and then gives up during testing. 我想JVM尝试先解决首先提供的javax类,然后在测试期间放弃。 I would figure that declaring scope for test would take precedence but that appears to not be the case in my situation. 我认为宣布测试范围优先,但在我的情况下似乎并非如此。 Hope this helps someone. 希望这有助于某人。

got same problem compiling with netbeans 7.2.1. 用netbeans 7.2.1编译同样的问题。 However the output specified one of my own java source files as having "absent code attribute.......etc" 但是输出指定我自己的一个java源文件具有“缺少代码属性.......等”

At same time, I could compile and run same project using JDeveloper. 同时,我可以使用JDeveloper编译和运行相同的项目。 After a few "cleans" and restarts the netbeans still threw up the same problem. 经过一些“清理”并重新启动后,netbeans仍然引发了同样的问题。

I finally fixed it by adding a main method into the java being reported as having "absent code attribute" and using same as the debug target. 我最后通过在报告为具有“缺少代码属性”并使用与调试目标相同的java中添加main方法来修复它。 All returned to normal. 全部恢复正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类文件javax / servlet / ServletException中不是本机或抽象的方法中的Embedded Jetty Absent Code属性 - Embedded Jetty Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException Struts2单元测试给出错误:类文件javax / servlet / ServletException中不是本机或抽象的方法中的缺少Code属性 - Struts2 Unit test gives the error: Absent Code attribute in method that is not native or abstract in class file javax/servlet/ServletException 在类文件javax / faces / webapp / FacesServlet中的非本机或抽象方法中的Absent Code属性 - Absent Code attribute in method that is not native or abstract in class file javax/faces/webapp/FacesServlet Java EE 6中类文件javax / mail / MessagingException中不是本机或抽象的方法中的缺少Code属性 - Absent Code attribute in method that is not native or abstract in class file javax/mail/MessagingException in Java EE 6 ClassFormatError:在类文件 javax/mail/MessagingException 中非本机或抽象的方法中缺少代码属性 - ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/MessagingException class 文件 javax/validation/ConstraintViolationException 中非本机或抽象方法中的缺失代码属性 - Absent Code attribute in method that is not native or abstract in class file javax/validation/ConstraintViolationException java.lang.ClassFormatError:类文件javax / faces / FacesException中不是本机或抽象的方法中的缺少Code属性 - java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/FacesException java.lang.ClassFormatError:在类文件 javax/mail/MessagingException 中非本机或抽象的方法中缺少代码属性 - java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/MessagingException 类文件javax / transaction / SystemException中不是本机或抽象的方法中的缺少Code属性 - Absent Code attribute in method that is not native or abstract in class file javax/transaction/SystemException java.lang.ClassFormatError:类文件javax / mail / internet / ParseException中不是本机或抽象的方法中的缺少Code属性 - java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/internet/ParseException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM