Java Eclipse 创建的“src”目录是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2637735/
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
What is "src" directory created by Eclipse?
提问by Roman
I just installed Eclipse.
The Eclipse created the "workspace" folder.
In this folder I created a "game" sub-folder (for my class called "game"). I have already .java files for that project (I wrote them in a text editor before I started to use Eclipse).
I put all my .java file into the "game" directory.
In Eclipse I created a "New Java Project" from existing code.
我刚刚安装了 Eclipse。
Eclipse 创建了“工作区”文件夹。
在这个文件夹中,我创建了一个“游戏”子文件夹(我的班级叫做“游戏”)。我已经有该项目的 .java 文件(在开始使用 Eclipse 之前,我在文本编辑器中编写了它们)。
我把我所有的 .java 文件放到了“game”目录中。
在 Eclipse 中,我从现有代码创建了一个“新 Java 项目”。
What wanders me is that the Eclipse create a "src" sub-folder into my "game" folder. As far as I understand "src" stands for "source". But my source (.java files) is in the "game" (by the construction).
让我感到困惑的是 Eclipse 在我的“游戏”文件夹中创建了一个“src”子文件夹。据我了解,“src”代表“来源”。但是我的源代码(.java 文件)在“游戏”中(通过构造)。
Am I doing something wrong?
难道我做错了什么?
ADDED:
添加:
I still cannot solve the problem. The whole day I am trying to start programming in Eclipse using existing code. It's incredibly complicated.
我仍然无法解决问题。我一整天都在尝试使用现有代码在 Eclipse 中开始编程。这非常复杂。
Should I "Import Existing Project into Workspace" or should I "Create New Java Project from Existing code".
Should I create "src" folder by hands and put in "workspace"?
Should I create folders for packages or Eclipse will do it by itself?
Should I copy my .java files to the package directory before or after I create a project in Eclipse?
我应该“将现有项目导入工作区”还是“从现有代码创建新的 Java 项目”。
我应该手动创建“src”文件夹并放入“工作区”吗?
我应该为包创建文件夹还是 Eclipse 会自己做?
在 Eclipse 中创建项目之前或之后,我应该将我的 .java 文件复制到包目录吗?
采纳答案by VonC
I would recommend keeping your sources separate from the eclipse workspace, and then use the function:
我建议将您的源代码与 eclipse 工作区分开,然后使用该函数:
Import existing project into workspace.
将现有项目导入工作区。
That way you can keep your project under source control, while leaving Eclipse manage its workspace (located elsewhere) on its own.
这样,您可以将项目置于源代码控制之下,同时让 Eclipse 自行管理其工作区(位于其他地方)。
If you have only sources (anywhere you want), but no Eclipse project, all you need to do create a New Java project, and select your external directory as root directory for your sources.
如果您只有源代码(您想要的任何地方),但没有 Eclipse 项目,那么您只需创建一个新的 Java 项目,并选择您的外部目录作为源代码的根目录。
selecting "Create project from existing sources"
选择“从现有源创建项目”
回答by Jim Blackler
The convention for Java is that your Java files are arranged by namespace under a 'src' directory. So if your application's namespace is com.example.myGame
your Java files will be located thus src\com\example\myGame\MyClass.java
.
Java 的约定是您的 Java 文件按命名空间排列在“src”目录下。因此,如果您的应用程序的命名空间是com.example.myGame
您的 Java 文件,那么src\com\example\myGame\MyClass.java
.
回答by Vincent Ramdhanie
Eclipse attempts to enforce a folder structure that is easy to maintain for all applications. You are not doing anything wrong. But you do have the option to select a different location for your source files but...everyone else expects your source code to be in src so why not.
Eclipse 尝试为所有应用程序强制实施易于维护的文件夹结构。你没有做错任何事。但是您确实可以选择为源文件选择不同的位置,但是……其他人都希望您的源代码位于 src 中,所以为什么不呢。
On the New Project screen you can choose the location where you want your source files or configure the default location if you are not happy with src.
在 New Project 屏幕上,您可以选择源文件所在的位置,或者如果您对 src 不满意,则配置默认位置。
回答by bakkal
src
is where Java IDEs (at least Eclipse and NetBeans) put the source files, it is pretty much standard, and the hierarchy of the folder inside it has to match your Java packages names.
src
是 Java IDE(至少 Eclipse 和 NetBeans)放置源文件的地方,它非常标准,并且其中文件夹的层次结构必须与您的 Java 包名称相匹配。