java.lang.ClassFormatError: Absent Code attribute...javax/xml/rpc/ServiceException

来源:互联网 发布:java技术培训 编辑:程序博客网 时间:2024/06/04 19:32


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

解决方式:由于在pom文件中添加了上面的内容导致一个异常:  删除这个依赖之后, 问题就没有了,


下面是我在网络找到的一篇分析这个异常的文章:

What's the cause of this exception:java.lang.ClassFormatError: Absent Code?

版本 6  

创建于:2010-3-21 上午12:57作者 Dan Allen - 最后修改:  2010-6-11 上午10:46 作者 Dan Allen

When running a test suite that includes Arquillian test cases,you may be encountering the following exception:

 

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file [Fully-qualified class name]    at java.lang.ClassLoader.defineClass1(Native Method)    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)

 

This problem is likely the result of having the javax:javeee-api(or javax:javaee-web-api) library on your test classpath. If you have a Mavenproject, you likely have the following dependency in your POM file:

 

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

 

This dependency provides you with the Java EE APIs, not theimplementations. While this dependency works for compiling, it cannot be usedfor executing code (that includes tests).

 

Background

 

When these artifacts were published to the Maven repository, Sunstripped out the code from classes that are classified as"implementations". So all the interfaces are code complete, yet anyabstract class or implementation class has no code in it. Any attempt to usethat class will likely blow up. That's why Arquillian is failing.

 

Here's an excerpt from the argument as to why Sun did this:

When one compiles, they want to run as well. By the way, we havebeen promoting full set of Java EE APIs which can only be used for compilation- they are stripped off method details. That way, user can't take thoseartifacts and try to use it in runtime.

The workaround is to not use javax.javaee-api but rather use theindividual, "real" artifacts that you need. Unfortunately, there isno Maven scope available that will exclude a dependency from the testclasspath.

 

There are two solutions to this problem.

 

Solution #1: Maven profiles

 

If you writing tests for an embedded Java EE container, then thecontainer is going to be on your test classpath. That container will have allthe APIs you need to compile. Therefore, you use the Java EE API for yourdefault profile, but then replace it with the target container JAR in theprofile you are using to run the tests. You can see an example of this setup inthe JUnit or TestNG Arquilian example POMs.

 

Solution #2: JBoss Java EE Spec Artifact

 

The other solution, which actually applies in both cases, is touse the Java EE spec artifact provided by JBoss, which does not reference anystripped classes.

 

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



阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 鹅卵石制砂机价格 pxj制砂机 制砂机企业 哪种制砂机好 制沙机械 制砂机品牌哪个好 制砂机生产线厂家 立式冲击制砂机 山东制砂机厂家 大型全自动制香机 鹅卵石制砂机生产线 制香机设备 制砂机设备生产厂家 制砂机专业生产厂家 全自动制香机器设备 制沙机图片 求购制沙机 制沙机厂家 哪里有制沙机 制沙机种类 制沙机配件 鹅卵石制沙机 小型制沙机价格 制沙机多少钱一套 青石制沙机 新型制沙机价格 冲击制沙机 鹅卵石制沙机报价 卵石制沙机 玄武岩制沙机 冲击式制沙机 移动制沙机 复合制沙机 岩石制沙机 vsi制沙机 碎沙机价格 建筑制沙机 立式制沙机 风化石制沙机 制沙机抛料头 碎沙机