英文:
Doubts about package naming convention and project management in Java
问题
我对Java中的包命名有点困惑。
我知道建议以域名开头作为包名,例如:
com.aimforthebushes.packagename
,并且有一个文件夹结构与包命名方案相对应:/com/aimforthebusches/packagename
我开始使用IntelliJ,当创建项目时,它默认创建了几个文件夹src
和out
。
我有三个问题:
1.- 如果我遵循命名约定,是不是意味着我必须在src
文件夹内创建com.aimforthebushes.packagename
这样的文件夹结构?
2.- 我需要为每个项目创建相同的文件夹结构,还是可以都放在同一个域名下?例如:
-
/ProjectName/com/aimforthebushes/packagename
或者
-
/com/aimforthebusches/projectname/packagename
3.- 如果我可以将所有项目放在相同的域名下(因此具有相同的文件夹结构),我该如何在IntelliJ中操作?
提前谢谢您。
英文:
I am a bit confused about package naming in Java.
I know that it's recommended to begin the package name with a domain name like:
com.aimforthebushes.packagename
and that there is a folder structure that equals the package naming scheme: /com/aimforthebusches/packagename
I am beginning to use IntelliJ and when a project is created it makes by default a couple of folders src
and out
I have three questions:
1.- If I am following the naming convention does it means that I have to create the folder structure com.aimforthebushes.packagename
inside src
?
2.- Do I need to create the same folder structure for every project or can I put them all under the same domain? ie:
-
/ProjectName/com/aimforthebushes/packagename
or
-
/com/aimforthebusches/projectname/packagename
3.- If I can put all the projects under the same domain name (and thus same folder structure) how to I do that on IntelliJ?
Thank you in advance.
答案1
得分: 0
以下是翻译好的部分:
这种目录结构的背后原因是为了更轻松地维护大型项目。如果您的项目不是很大,并且您预计它不会变得很大,您可以忽略这些约定(我不建议这样做),只需在喜欢的目录中创建Java文件。
您应该阅读更多关于Java包和模块的内容。
- 是的
- 如果您有两个不同的项目,它们应该位于不同的文件夹内,因为它们是两个不同的项目。但是如果您说的是项目内不同的模块,您可以使用相同的目录。
例如,您可能对单个项目有以下目录结构,其中basic
,objects
和utils
是同一项目的三个不同模块。
src
└── org
└── thisaru
└── myproject
├── basic
├── objects
└── utils
- 您不应该将两个项目放在同一个目录中。
英文:
The reason behind this directory structuring is to maintain larger projects, easily. If your project is not that large, and you expect it not to grow to a larger size, you can omit these conventions (I don't advice it), and just create the Java files inside a directory you like.
You should read more about java packages and modules.
- Yes
- If you have two different projects, they should be inside different folders, because they are two different projects. But if you are talking about different modules inside a project, you can use the same directories.
For an example, you may have the following directory structure for a single project, where basic
, objects
and utils
are three different modules of the same project.
src
└── org
└── thisaru
└── myproject
├── basic
├── objects
└── utils
- You should not put two projects in the same directory.
专注分享java语言的经验与见解,让所有开发者获益!
评论