Java 我可以在 Eclipse 中的包内创建文件夹吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19968415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I create folder inside package in eclipse?
提问by Xyzk
I have project, with source folder "app", inside this package I have package "models". Can I create folder or any other kind of subdirectory within this package? So that eventually I would have something like
我有项目,带有源文件夹“app”,在这个包中我有包“models”。我可以在这个包中创建文件夹或任何其他类型的子目录吗?所以最终我会有类似的东西
-app
-models
-Folder1
-file1
-file2
-Folder2
-file3
-file4
When I try to force creating folder inside (by clicking new->other->folder), I cannot add anything to it.
当我尝试在内部强制创建文件夹时(通过单击 new->other->folder),我无法向其中添加任何内容。
采纳答案by Julien Bourdon
Packages and folders are slightly different conceptually.
包和文件夹在概念上略有不同。
You generally group your classes that deal with the same functionality in the same package. For example the core classes, the model of your app can be in com.example.myapp.core and the ui classes in com.example.myapp.ui .These packages are represented on the disk by a folder structure.
您通常将处理相同功能的类分组在同一个包中。例如核心类,您的应用程序模型可以在 com.example.myapp.core 中,ui 类可以在 com.example.myapp.ui 中。这些包在磁盘上通过文件夹结构表示。
In my opinion, you should not change this package structure to add files that are not Java classes. I would suggest to add a resources
folder at the top of your app tree so that your data and your classes are separated.
在我看来,您不应该更改此包结构以添加不是 Java 类的文件。我建议resources
在应用程序树的顶部添加一个文件夹,以便将数据和类分开。
But if you want to just add subpackage, do not create a new folder, just create a new package such as app.models.Folder1.file1
and you will get the structure you want.
但是如果你只想添加子包,不要创建新文件夹,只需创建一个新包,例如app.models.Folder1.file1
,你就会得到你想要的结构。
You can refer to this question to know more about the packaging conventions: Are there best practices for (Java) package organisation?
您可以参考此问题以了解有关打包约定的更多信息:是否有 (Java) 包组织的最佳实践?
回答by Scary Wombat
a folder in a package is just another package, so you want new->packagethen type in app.models.folder1
包中的文件夹只是另一个包,因此您需要new->package然后输入 app.models.folder1
回答by cmd
Creating a folder within a package simply creates a new package
在包内创建文件夹只会创建一个新包
e.g. The folder structure
例如文件夹结构
- app
- models
equates to package app.models
相当于包 app.models
Adding a new folder, Folder1
to this structure
在Folder1
此结构中添加一个新文件夹
e.g.
例如
-app
-models
-Folder1
equates to the package app.models.Folder1
相当于包 app.models.Folder1