Error running JUnit unit test after project add MAVEN support

Source: Internet
Author: User
Tags abstract mail

After the project adds MAVEN support, run the JUnit unit test and an error occurs:

ERROR in Ch.qos.logback.core.joran.action.appenderaction-could not create a appender of type [COM.TRAVELSKY.TDP.P KgStock.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 Ch.qos.logback.core.util.OptionHelper.instantiateByClassName (optionhelper.java:54) at ... (omitting printing information) at at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (remotetestrunner.java:197) caused by : Java.lang.ClassFormatError:Absent Code in method, not native, or abstract in class file Javax/mail/in Ternet/addressexception at the Java.lang.ClassLoader.defineClass1 (Native method) at ..... (omitting print information) at ... 41Common frames omitted ERROR in Ch.qos.logback.core.joran.spi.interpreter@192:115-actionexception into Action for Tag [Appender] Ch.qos.logback.core.joran.spi.ActionException:ch.qos.logback.core.util.DynamicClassLoadingExce ption: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.L Ogback.core.joran.action.AppenderAction.begin (appenderaction.java:82) at ... (omitting printing information) 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 Ch.qos.logback.core.Util. Optionhelper.instantiatebyclassname (optionhelper.java:54) at ... Common frames omitted caused by:java.lang.ClassFormatError:Absent Code in method and 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 Java.lang.ClassLoader.defineClass1 (Native Meth OD) at ..... (omitting print information) at ... Common frames omitted

Unit test failed to find the cause and found the following problem:

1, Maven rely on the use of Javeee.jar version is high, which contains mail-related interfaces, and Mail.jar conflict;

2, Javaee.jar contains the mail-related interface implementation class;

3, MyEclipse Javaee.jar version and the version of MyEclipse itself: MyEclipse6.5 with the Javaee.jar does not contain mail-related interfaces, The MyEclipse8.0 Javaee.jar contains the mail-related interface, and also contains the implementation of the interface.

4, the project directly used in the Mail.jar class and method;

This bug occurs because of class conflicts, so remove conflicting classes; But how do you choose?

The analysis is as follows:

A, this project is a Web project, so Javaee.jar should be retained;

B, Javaee.jar contains the implementation of mail-related interfaces, so javaee.jar should be retained;

C, the project directly used in the Mail.jar interface, so the Mail.jar should be retained;

So he got into a dilemma.

However, there is a rather humble way, maven dependencies do not add Java EE dependencies, using MyEclipse javeee dependencies, and if the dependency contains mail-related interfaces, delete them, so the problem is resolved.

However, some people will ask, if I changed the version of MyEclipse, not to be modified every time, if forgotten, it is a waste of time ... So the solution is only temporary, and the more orthodox solution is the following:

Place the dependencies of <scope>provided</scope> in Pom.xml on the back of other dependencies without deleting any dependencies.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/tools/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.