Why is my Eclipse Java package being treated as a folder?

后端 未结 14 646
失恋的感觉
失恋的感觉 2021-01-04 00:14

My Eclipse Java package is treated as a folder; can anyone suggest what\'s wrong?

相关标签:
14条回答
  • 2021-01-04 00:37

    Well, I actually think you might don't even need the answer anymore (almost two years later) but I will share anyway to document (just found a solution that others could use).

    The problem: while searching some packages I accidentally clicked "Add to build path" in a package and after I ctrl+z, the package had became a folder.

    The solution I found was on the .classpath. There was a line there with the name of the package I had just added to the build path (even after the Ctrl+Z). Delete that line and after refreshing the project your whole src folder will be turned into a normal folder.

    Then right click your src, following this path: src > Build Path > Use as Source Folder.

    This solved the problem, I just tested the result. Hope it helps.

    0 讨论(0)
  • 2021-01-04 00:38

    I have faced the same issue and found the solution, as to add Java Nature in .project file of the current application.


    Project natures are used in the Eclipse IDE in order to configure projects in the workspace. One project may have several project natures. The most popular project nature is org.eclipse.jdt.core.javanature, which is used to indicate that a project is a Java project.

    Add org.eclipse.jdt.core.javanature and its corresponding builder in the .project file of an application as shown below:

    <projectDescription>
        <name>MyJavaApplication</name>
        <comment></comment>
        <projects></projects>
        <buildSpec>
            <buildCommand>
                <name>org.eclipse.jdt.core.javabuilder</name>
                <arguments></arguments>
            </buildCommand>
            <!-- ... -->
        </buildSpec>
        <natures>
            <nature>org.eclipse.jdt.core.javanature</nature>
            <!-- ... -->
        </natures>
    </projectDescription>
    

    Project view as Package structure:

    enter image description here

    Projects and its dependent modules as Hierarchical structure.

    Package Explorer / View Menu / Package Presentation... / Hierarchical
    
    0 讨论(0)
提交回复
热议问题