Java 项目与 Maven 项目 (Eclipse),需要澄清目录结构

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

Java Project vs Maven Project (Eclipse), dir structure clarification needed

javamaven

提问by James Raitsev

When i create a new Maven project in Eclipse, directory structure contains both src/main/javaand src/main(down below)

当我在 Eclipse 中创建一个新的 Maven 项目时,目录结构包含src/main/javasrc/main(在下面)

Question: I understand my code should fall under src/main/java, what is the purpose of the src/main? Why does Eclipse create it?

问题:我知道我的代码应该属于src/main/java, 的目的是src/main什么?为什么 Eclipse 会创建它?

enter image description here

在此处输入图片说明

采纳答案by Paul Whelan

For src/main/java to exist src/main/ must first exist so eclipse just shows you all the folders in your project including src/main/

要使 src/main/java 存在 src/main/ 必须首先存在,因此 eclipse 只会向您显示项目中的所有文件夹,包括 src/main/

If you want to remove them from your view in package explorer, you can create a filter for the package explorer view and exclude Non-Java elements.

如果您想从包资源管理器的视图中删除它们,您可以为包资源管理器视图创建一个过滤器并排除Non-Java 元素

Look for the down arrow in the top right of the package explorer view for the filters option.

在包浏览器视图右上角寻找过滤器选项的向下箭头。

回答by Oh Chin Boon

src/main/javais Maven's standard layout for placement of your Java source codes.

src/main/java是 Maven 用于放置 Java 源代码的标准布局。

Check http://java.sg/maven-standard-directory-layout/for a list of standard Maven directories.

检查http://java.sg/maven-standard-directory-layout/以获取标准 Maven 目录列表。

src/main/java       Application/Library sources
src/main/resources  Application/Library resources
src/main/filters    Resource filter files
src/main/assembly   Assembly descriptors
src/main/config     Configuration files
src/main/webapp     Web application sources
src/test/java       Test sources
src/test/resources  Test resources
src/test/filters    Test resource filter files
src/site        Site
LICENSE.txt     Project's license
NOTICE.txt      Notices and attributions required by libraries that the project depends on
README.txt      Project's readme

回答by JustinKSU

You can have other sub-directories under src/main that are not source files. If you see Maven documentation you need to have resource files under src/main/resources. Obviously the parent directory src/main needs to be created to create child directories.

您可以在 src/main 下拥有其他不是源文件的子目录。如果你看到 Maven 文档,你需要在 src/main/resources 下有资源文件。显然需要创建父目录 src/main 来创建子目录。