Eclipse: The resource is not on the build path of a Java project

后端 未结 13 1381
栀梦
栀梦 2020-12-04 17:23

I have been given a Source Folder (src) of a Java Project. I have created a .project file, kept it inside that folder and imported that Project int

相关标签:
13条回答
  • 2020-12-04 17:52

    Refactor the name of the folder src/main/resource to src/main/java.

    Right click the project > Build Path > Use Source Folder.

    0 讨论(0)
  • 2020-12-04 17:52

    If you imported a project from external source with pom.xml after import, go to Project->Properties->Maven and enable Java EE - This will resolve the error

    0 讨论(0)
  • 2020-12-04 17:53

    Recently I met a similar problem. when importing a project without .project, a default empty .project generated without builders. here is an example to make it work.

    <buildSpec>
        <buildCommand>
                <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
    
    0 讨论(0)
  • 2020-12-04 17:55

    You can add the src folder to build path by:

    1. Select Java perspective.
    2. Right click on src folder.
    3. Select Build Path > Use a source folder.

    And you are done. Hope this help.

    EDIT: Refer to the Eclipse documentation

    0 讨论(0)
  • 2020-12-04 17:59

    I found similar issue and fixed it by correcting .project file. For java project .project file must have below tag within natures

    org.eclipse.jdt.core.javanature


    Example of complete .project file

    <?xml version="1.0" encoding="UTF-8"?>
    <projectDescription>
        <name>SampleProjectName</name>
        <comment></comment>
        <projects>
        </projects>
        <buildSpec>
            <buildCommand>
                <name>org.maven.ide.eclipse.maven2Builder</name>
                <arguments>
                </arguments>
            </buildCommand>
            <buildCommand>
                <name>oracle.eclipse.tools.weblogic.sharedLibraryFrameworkValidator</name>
                <arguments>
                </arguments>
            </buildCommand>
        </buildSpec>
        <natures>
            <nature>org.eclipse.jdt.core.javanature</nature>
        </natures>
    </projectDescription>
    
    0 讨论(0)
  • 2020-12-04 18:01

    Looks like you created your Java class under src/main/resources instead of src/main/java

    0 讨论(0)
提交回复
热议问题