The reason and solution of the classnotfoundexception of JUnit report after project integration maven

Source: Internet
Author: User

Prerequisite: The original project all run normally, unit test normal execution.

The project began using MAVEN management and found that the original JUnit test could not be performed and the class could not be found (java.lang.ClassNotFoundException). In any case modifying the MAVEN configuration, the error is still.

Analysis Reason:

MyEclipse is able to identify items based on the . Project file, and the project's directory structure is defined in the . Classpath file. MyEclipse's JUnit plug-in is also based on the above file to find the source code and class file storage directory. After the project integrates MAVEN, the class file generation directory is specified by the Pom.xml file by executing the MAVEN command.

The project directory structure that MAVEN uses by default differs from the default directory structures in MyEclipse, when the directory specified in pom.xml file and the directory specified by the . Classpath file are not the same, and the error mentioned above is reported.

Therefore, when the project integrates MAVEN, the following are the areas to be noted when performing junit tests:

The following configuration in the Pom.xml file

should correspond to the following configuration in the. classpath file.

After this configuration, JUnit can execute correctly without affecting the functionality of MAVEN's packaging, publishing, and so on.

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.