eclipse Springsource Tool中src/main/java和src有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6205803/
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 the difference between src/main/java and src in Springsource Tool
提问by okysabeni
I'm learning to use Springsource Tool Suite (STS) and the Spring framework for development. I am trying out the Amazon AWS SDK for eclipse and decided to install it into STS. When I follow create a new AWS project, it puts the .java file under src instead of src/main/java and when I try to build that, it says
我正在学习使用 Springsource Tool Suite (STS) 和 Spring 框架进行开发。我正在试用 Amazon AWS SDK for eclipse 并决定将其安装到 STS 中。当我创建一个新的 AWS 项目时,它将 .java 文件放在 src 而不是 src/main/java 下,当我尝试构建它时,它说
"There is no main" or something like that.
“没有主要”或类似的东西。
But, when I move the AwsConsoleApp.java and the AwsCredentials.properties to src/main/java then (default package), I can run the file as a Java application.
但是,当我将 AwsConsoleApp.java 和 AwsCredentials.properties 移动到 src/main/java 然后(默认包)时,我可以将文件作为 Java 应用程序运行。
My question is, what is the difference between src/main/java
-> default package and src -> main. I've attached an image to clarify things:
我的问题是,src/main/java
-> default package 和 src -> main之间有什么区别。我附上了一张图片来澄清事情:
回答by Danail Nachev
Answer:
回答:
Each Java project in Eclipse (and STS as well), has associated build path, where it is specified, which folders in the project contains java classes. Thus, the difference between src/
and src/main/java
is that src/main/java
is configured as a folder, containing java classes (or source folder in Eclipse terminology), while src/
folder just contains the source folder.
Eclipse(以及 STS)中的每个 Java 项目都有关联的构建路径,它在何处被指定,项目中的哪些文件夹包含 Java 类。因此, 和 之间的区别在于src/
,src/main/java
它src/main/java
被配置为一个文件夹,其中包含 java 类(或 Eclipse 术语src/
中的源文件夹),而文件夹仅包含源文件夹。
More information can be found in Eclipse Help.
更多信息可以在Eclipse 帮助中找到。
I'm not sure what has caused that your Java classes end up in the wrong folder, but this means that they are not in the classpath of the project. So, when you run your application as Java application, it complains that it cannot find main()
method (which is the default entry point for any Java application).
我不确定是什么导致您的 Java 类最终出现在错误的文件夹中,但这意味着它们不在项目的类路径中。因此,当您将应用程序作为 Java 应用程序运行时,它会抱怨它找不到main()
方法(这是任何 Java 应用程序的默认入口点)。
Everything comes into place, when you move your classes under the default package in src/main/java
: Eclipse finds your Java classes and the main()
method.
当您将您的类移动到src/main/java
: 中的默认包下时,一切都已就位:Eclipse 会找到您的 Java 类和main()
方法。