java 推荐的源代码管理目录结构?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41513/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 10:49:34  来源:igfitidea点击:

Recommended Source Control Directory Structure?

javasvnjakarta-eeversion-controlcode-organization

提问by

I am going to be using Subversion for source control on a new J2EE web application. What directory structure will you recommend for organizing code, tests and documentation?

我将在新的 J2EE Web 应用程序上使用 Subversion 进行源代码控制。你会推荐什么目录结构来组织代码、测试和文档?

回答by Mendelt

I usually have

我通常有

Project Directory
  src - actual source
  doc - documentation
  lib - libraries referenced from source
  dep - installation files for dependencies that don't fit in lib
  db  - database installation script

In work with Visual Studio, I'm not sure if this works the same in the java world. But i usually put stuff in different project folders in src. For each source project there's a separate test project. Build files go in the main project directory. I usually put a README there too documenting how to setup the project if it needs more than just checking out.

在使用 Visual Studio 时,我不确定这在 Java 世界中是否同样有效。但我通常把东西放在 src 的不同项目文件夹中。每个源项目都有一个单独的测试项目。构建文件位于主项目目录中。如果项目需要的不仅仅是检查,我通常也会在那里放一个自述文件来记录如何设置项目。

EDIT: This is the structure for a single working checkout of the project. It will be duplicated for each branch/tag in your revision control system (remember, in most SVN system, copies are cheap). The above example under Subversion would look like:

编辑:这是项目的单个工作签出的结构。它将为您的修订控制系统中的每个分支/标签复制(请记住,在大多数 SVN 系统中,副本很便宜)。Subversion 下的上述示例如下所示:

/project
    /trunk
        /src
        /doc
        /...
    /branches
        /feature1
            /src
            /doc
            /...
        /feature2
            /src
            /doc
            /...

回答by matt b

To expand on what Mendelt Siebenga suggested, I would also add a webdirectory (for JSP files, WEB-INF, web.xml, etc).

为了扩展 Mendelt Siebenga 的建议,我还将添加一个web目录(用于 JSP 文件、WEB-INF、web.xml 等)。

Tests should go in a folder named testthat is a sibling of the main srcfolder - this way your unit test classes can have the same package name as the source code being tested (to ease with situations where you want to test protected methods or classes, for example... see the JUnit FAQ for this, and this question also on Where should I put my test files?).

测试应该放在一个名test为主src文件夹的同级文件夹中 - 这样你的单元测试类可以与被测试的源代码具有相同的包名称(为了缓解你想要测试受保护方法或类的情况,例如示例...请参阅JUnit 常见问题解答,此问题也关于我应该将测试文件放在哪里?)。

I haven't had much use for it myself, but a Maven project will also create a resourcesfolder alongside the src folder for non-source code that you want to package/deploy along with the main source code - things such as properties files, resources bundles, etc. Your mileage may vary on this one.

我自己并没有太多用处,但是 Maven 项目还会resources在 src 文件夹旁边为非源代码创建一个文件夹,这些非源代码要与主要源代码一起打包/部署 - 诸如属性文件、资源之类的东西捆绑包等。您的里程可能会有所不同。

回答by ryan

I use Eclipse for creating J2EE web applications and this will create the following project structure:

我使用 Eclipse 创建 J2EE Web 应用程序,这将创建以下项目结构:

WebAppName\
    \lib
    \src
    \tests
    etc...

I would then create an SVN folder on our trunk called WebAppNameProject. Within this folder I would create folders called WebAppNameSource, Documentation etc. Within the WebAppNameSource folder I would place the project source generated by Eclipse. Thus I would have the following folder structure in SVN:

然后我会在我们的主干上创建一个名为 WebAppNameProject 的 SVN 文件夹。在此文件夹中,我将创建名为 WebAppNameSource、Documentation 等的文件夹。在 WebAppNameSource 文件夹中,我将放置由 Eclipse 生成的项目源。因此,我将在 SVN 中具有以下文件夹结构:

\svn\trunk\WebAppNameProject
    \WebAppNameSource
        \lib
        \src
        \tests
        etc...
    \Documentation 

Hope this helps.

希望这可以帮助。