“src / main / java”约定的优点是什么? [英] What is the advantage of the 'src/main/java'' convention?
问题描述
我注意到很多专案都有以下结构:
I've noticed that a lot of projects have the following structure:
- Project-A
- bin
- lib
- src
- main
- java
- RootLevelPackageClass.java
我目前使用以下约定(因为我的项目是100%java):
I currently use the following convention (as my projects are 100% java):
- Project-A
- bin
- lib
- src
- RootLevelPackageClass.java
我目前不使用Maven,但我想知道这是否是一个Maven约定,或者如果有另一个原因。
I'm not currently using Maven but am wondering if this is a Maven convention or not or if there is another reason. Can someone explain why the first version is so popular these days and if I should adopt this new convention or not?
Chris
推荐答案
主要好处是将
test
目录作为src
与main
中的目录结构具有相同的目录结构:Main benefit is in having the
test
directory as subdirectory ofsrc
with the same directory structure as the one inmain
:- bin
- lib
- src
- main
- java
- RootLevelPackageClass.java
- java
- TestRootLevelPackageClass.java
RootLevelPackageClass
的所有包私有方法都将可见,TestRootLevelPackageClass
。由于测试代码也是源代码,它的位置应该在src
目录下。All package private methods of
RootLevelPackageClass
will be visible, i.e. testable fromTestRootLevelPackageClass
. Since the testing code is also source its place should be undersrc
directory.这篇关于“src / main / java”约定的优点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- java
- main
< A
- java
- main