java 源文件夹和(普通)文件夹有什么区别

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

What is the difference between a source folder and a (normal) folder

javaidedirectorysrc

提问by Eric Francis

I'm following this guide: Spring MVCand I realized that I do not know the difference between a source folder (src) and a plain folder.

我正在遵循本指南:Spring MVC,我意识到我不知道源文件夹(src)和普通文件夹之间的区别。

I'm using eclipse, so maybe the difference is only useful in an IDE?

我正在使用 eclipse,所以也许差异仅在 IDE 中有用?

Also, I've noticed that java classes tend to go in src folders; whilst every other file goes into a plain folder (or the project root folder).

另外,我注意到 java 类倾向于放在 src 文件夹中;而其他所有文件都进入一个普通文件夹(或项目根文件夹)。

So, What is the significance of the source folder (src)? Why use a source folder over a plain folder?

那么,源文件夹(src)的意义是什么?为什么要在普通文件夹上使用源文件夹?

Thanks!

谢谢!

回答by admenva

A source folder is marked by Eclipse as containing java sources. Then, when you compile your project Eclipse will look for your source code into all your source folders.

Eclipse 将源文件夹标记为包含 Java 源。然后,当您编译您的项目时,Eclipse 将在您的所有源文件夹中查找您的源代码。

You can make any folder become a source folder adding it to the java build path. Thus, next time you compile your project Eclipse will also look for java classes in that folder.

您可以使任何文件夹成为源文件夹,将其添加到 java 构建路径中。因此,下次编译项目时,Eclipse 还会在该文件夹中查找 java 类。

回答by TimeTrap

The source folder contains your source code in relation to the project's build path. In the below Spring Boot project com.example.demois in the classpath, indicated by package icon (and the .classpath file in the project's root, found outside of eclipse in the project's root folder). The path src/main/java/is where this package is in relation to the root of the project.

源文件夹包含与项目构建路径相关的源代码。在下面的 Spring Boot 项目com.example.demo位于类路径中,由包图标指示(以及项目根目录中的 .classpath 文件,在项目的根文件夹中的 eclipse 之外找到)。路径src/main/java/是此包相对于项目根目录的位置。

enter image description here

在此处输入图片说明

You can remove a source folder (eg src/test/java/) from the build path by right-clicking on the folder Build Path > Remove from Build Path. To add it back to back by right-clicking on the folder that will contain your build path (eg src/test/java/) and then choosing Build Path > Use as Source Folder.

您可以src/test/java/通过右键单击文件夹 Build Path > Remove from Build Path 从构建路径中删除源文件夹(例如)。通过右键单击将包含构建路径的文件夹(例如src/test/java/),然后选择构建路径 > 用作源文件夹来将其背靠背添加。

enter image description here

在此处输入图片说明