[英]java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/MessagingException
I have a maven dependency for javaee Bibliothek.我对 javaee Bibliothek 有一个 maven 依赖。
<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.我在 Eclipse 中的某些类中遇到错误。
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.我添加了 javax.mail 依赖项。
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.5</version>
</dependency>
It did not not work.它没有用。 Any Idea??任何的想法??
It did not work because classes from javax/javaee-api/provided
dependency are specially constructed.它不起作用,因为来自javax/javaee-api/provided
依赖项的类是专门构造的。 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.简单地将javax.mail/mail/1.4.5
依赖项中的类添加到类路径没有帮助,因为javax/javaee-api/provided
中的类已经存在。 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
.单独使用javax.mail/mail/1.4.5
依赖可以解决您的问题,但很可能您还需要来自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.您可以做的是摆脱javax/javaee-api/provided
依赖项,例如从目标应用程序服务器javax/javaee-api/provided
依赖项中获取这些类。 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.这就是为什么您也可以将它与 JBoss 以外的其他应用程序服务器一起使用的原因。 It is same API as in your original dependency, but it contains normal classes.它与原始依赖项中的 API 相同,但它包含普通类。
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.反过来不行。
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使用 JDK 6 和 Tomcat 运行没有问题
如果您按以下顺序将它们添加到您的 pom 中:javax.mail javaee-web-api 它可以工作是非常合乎逻辑的,因为运行时首先从 javax.mail 找到必要的类(具有正确的实现),忽略任何类似的来自 javaee-web-api 的类(没有实现)。
In my case i use following order.在我的情况下,我使用以下顺序。 Work very well with JDK6.与 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.