“src / main / java”约定的优点是什么? [英] What is the advantage of the 'src/main/java'' convention?

查看:286
本文介绍了“src / main / java”约定的优点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到很多专案都有以下结构:

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 of src with the same directory structure as the one in main:


                < A


                • 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 from TestRootLevelPackageClass. Since the testing code is also source its place should be under src directory.

                        这篇关于“src / main / java”约定的优点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆