开发者

What is the difference between src/main/java and src in Springsource Tool

开发者 https://www.devze.com 2023-03-10 05:28 出处:网络
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 n

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

"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.

My question is, what is the difference between src/main/java -> default package and src -> main. I've attached an image to clarify things:

What is the difference between src/main/java and src in Springsource Tool


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.

More information can be found in Eclipse Help.

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).

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号