Error adding Java source directory (source folder) under Src/main in project after creating project with Maven

Source: Internet
Author: User

After creating a Web project with Maven, there is only resources under SRC, and then you want to add a source folder named Java in Src/main to store Java code, but eclipse reported the following error:

Cannot nest ' Tst/src/main/java ' inside ' tst/src/'. To enable the nesting exclude main/' from ' tst/src/'


The above error is a hint that the source folder you want to create already exists in classpath and cannot be created again. You may be very strange, I have not created, why I hint source folder already exists. This is because MAVEN has configured it by default when Maven creates the project, and as you can see from the project's Java build path, the source folder shown in the figure is missing, which is non-existent, Because Maven did not help you create the source folder in your project, as shown in the figure:



This time you may have doubts, since Maven does not really create source folder, then why not let me create Src/main/java. The reason is this, although the above figure shows that Src/main/java does not exist, but there is a place that has indeed been configured to Src/main/java to SRC. This file is the Classpath file, each project has a file, to configure the class and resource files under SRC path and the path to compile, the following figure:



Workaround:

Right-click the project--> "Properties"--> "Java Build path", remove the missing source folder, and then recreate the source folder in the project. After deletion, the corresponding SRC that is configured in the. Classpath under the project will also be removed.




=====================================================================================

Here is Maven's "Convention over Configuration" tutorial, which contains the project structure of MAVEN, these are the agreed specifications, you can see:

MAVEN conventions are better than configuration explanations


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.