项目添加Maven支持后,运行JUnit单元测试,出现一下错误:
ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not create an Appender of type [com.travelsky.tdp.pkgStock.integration.logback.appender.mail.SMTPAppender]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type com.travelsky.tdp.pkgStock.integration.logback.appender.mail.SMTPAppender at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type com.travelsky.tdp.pkgStock.integration.logback.appender.mail.SMTPAppender at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:54) at ......(省略打印信息) at at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/internet/AddressException at at java.lang.ClassLoader.defineClass1(Native Method) at .....(省略打印信息) at ... 41 common frames omitted ERROR in ch.qos.logback.core.joran.spi.Interpreter@192:115 - ActionException in Action for tag [appender] ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type com.travelsky.tdp.pkgStock.integration.logback.appender.mail.SMTPAppender at ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type com.travelsky.tdp.pkgStock.integration.logback.appender.mail.SMTPAppender at at ch.qos.logback.core.joran.action.AppenderAction.begin(AppenderAction.java:82) at ......(省略打印信息) at at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type com.travelsky.tdp.pkgStock.integration.logback.appender.mail.SMTPAppender at at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:54) at ... 39 common frames omitted Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file <SPAN style="COLOR: #ff0000"><STRONG>javax/mail/internet/<SPAN style="COLOR: #ff0000">Ad</SPAN>dressException</STRONG></SPAN> at at java.lang.ClassLoader.defineClass1(Native Method) at .....(省略打印信息) at ... 41 common frames omitted |
单元测试失败,查找原因,发现如下问题:
1、Maven依赖中使用的 javeee.jar 版本较高,里面包含了 mail相关的接口,和 mail.jar 相冲突;
2、javaee.jar 中包含了 mail相关接口的 实现类;
3、MyEclipse自带的javaee.jar 版本和 MyEclipse本身的版本有关:MyEclipse6.5自带的javaee.jar 中不包含mail相关的接口,而MyEclipse8.0自带的javaee.jar中包含了mail相关的接口,同时包含了接口的实现;
4、项目中直接用到了mail.jar中的类和方法;
此bug出现的原因是由于类冲突,因此去掉冲突的类即可;但是应该怎么选择呢?