1.1-point Maven (one)--ECLIPSE development maven Project Tip: Package Org.junit does not exist solution

Source: Internet
Author: User

1, the problem arises:

The MAVEN project execution unit test executes normally, but executes the MAVEN command test, reporting an exception:

Org.apache.maven.plugins:maven-compiler-plugin:2.5.1:testcompile (Default-testcompile) on project support: Compilation failure:compilation failure:
[ERROR] E:\workspace\support\src\test\java\com\test\spring\support\ TESTSPRINGCONTEXTHOLDER.JAVA:[7,16] Error: Package org.junit does not exist
[ERROR] E:\workspace\support\src\test\java\com\test\ spring\support\testspringcontextholder.java:[16,2] Error: Cannot find Symbol
[ERROR] Symbol:   class Test
[ERROR] Position: class Testspringcontextholder
[ERROR] E:\workspace\support\src\test\java\com\test\spring\support\ testspringcontextholder.java:[29,2] Error: Cannot find Symbol
[ERROR] Symbol:   class before
[ERROR] Position: Class Testspringcontextholder
[ERROR] e:\workspace\support\src\test\java\com\test\spring\support\testspringcontextholder.java:[43,5] Error: Symbol not found




2. Causes of the above errors:

1), MAVEN project, unit test and run using different classpath, test using Test-classpath, run using Classpath;
2), creating a MAVEN project using the JUnit default version is 3.8.1, which uses a programmatic approach, even if the Maven dependencies directory is introduced to JUnit, but is not available, only the build path can be used to add junit support

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>




3. Solution:

To increase the version of JUnit to 4.x, the configuration code is as follows:

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <!--The default version is 3.8.1, modified to 4.x, because 3.x is used in a programmatic way, 4.x is the form of annotations. -
            <version>4.11</version>
            <scope>test</scope>
        </dependency>




4, add: I posted above the exception directory located in ... \src\test\java\ ... No... \src\main\java\ ... , if the exception occurs in the main directory instead of the test directory, and the JUnit version is 4.x, the solution removes the scope attribute:

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <!--The default version is 3.8.1, modified to 4.x, because 3.x is used in a programmatic way, 4.x is the form of annotations. -
            <version>4.11</version>
            <!--Remove the scope scope, using the default compile, compile, test, run all valid scopes--
            <!--<scope>test</scope>-->
        </dependency>

Solution Reference: http://www.cnblogs.com/LiuChunfu/p/5598367.html

Related Article

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.