Creating a separate Folder in the same package… [ECLIPSE]

后端 未结 5 1718
一向
一向 2021-02-06 05:58

Is it possible in Eclipse to create a separate Folder in a package? When select \"new --> folder\", my eclipse version always creates a package. But i want the new folder to be

相关标签:
5条回答
  • 2021-02-06 06:33

    You need to exclude the folder from the source path

    0 讨论(0)
  • 2021-02-06 06:34

    What you might want to do, if you aren't putting code in that folder, is remove the folder from the build path. Right-click on the offending folder in eclipse and choose 'exclude from build path.'

    Or, you may want a different effect:

    Right click on your project and choose add new source folder. Then in that folder, add the correct package folder structure.

    You can have files in the same package located in different folders.

    0 讨论(0)
  • 2021-02-06 06:36

    In a source folder, all 'new' folders will be considered a new package. It's part of the Java spec that makes all folders from a root to be part of the package structure.

    0 讨论(0)
  • 2021-02-06 06:42

    As others have said, this is standard java behaviour and shouldn't really be worked around. You are probably better off creating another folder outside of the source folder.

    However there is a way to do it in Eclipse, be warned that this might come back to haunt you if you later try to build outside Eclipse as other tools won't honour these settings.

    You can exclude a folder from the source path by opening the project properties.

    Selecting Java Build Path->Source Select the appropriate source folder and select the Excluded: child item Hit the Edit... button. Select the Add button next to the Exclusion patterns: pane Add your folder and Finish/OK back to the editor.

    The matching resources will now be excluded from compilation within Eclipse. It will still appear as a package in the editor though.

    0 讨论(0)
  • 2021-02-06 06:42

    You want to create a new child package (bar) of the existing package. (com.foo)

    Select new package and name it "com.foo.bar". Eclipse will correctly place it under com.foo.

    FYI: Folders under any "source" folder are shown as packages. There is no physical difference except that they appear on the build path. As shown elsewhere you can exclude them but it's easier to just not put them under /src/... to begin with.

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