Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do maven projects have a src folder which has two empty sub-folders (main and test)

Tags:

java

maven

I am new to the java world. I created a simple java (maven) project and I see the packages and everything works perfectly. However I do see a src with two empty main and test folders. Any idea why?

enter image description here

EDIT: Adding more information to the answer The answer below is perfect. However on tinkering a little more I found a more compelling reason why it is shown like that in eclipse.

If the folder is in "Java build path" then those folders will be shown above in the specialized view. So you can create any folder and once you add that folder to the "Java build path" the view for that folder changes. Same if you remove an existing folder from the "Java build path" then it seems to go back as a normal tree view in the bottom.

like image 543
Mano Avatar asked Apr 11 '13 03:04

Mano


People also ask

What is the purpose of src folder?

The src stands for source. The /src folder comprises of the raw non-minified code. The /src folder is used to store the file with the primary purpose of reading (and/or editing) the code. The /src folder contains all the sources, i.e. the code which is required to be manipulated before it can be used.

What is the use of src main java in Maven?

As the name indicates, src/main is the most important directory of a Maven project. Anything that is supposed to be part of an artifact, be it a jar or war, should be present here. Its subdirectories are: src/main/java – Java source code for the artifact.

What should be in src folder?

The src directory contains all of the source material for building the project, its site and so on. It contains a subdirectory for each type: main for the main build artifact, test for the unit test code and resources, site and so on. Within artifact producing source directories (ie.

What is the difference between src main java and src?

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.


2 Answers

Folder are not empty. Look where your App.java is: src/main/java/com/nuance/spring

Eclipse hide you content on this place because that are special folders with special view above.

If you have other folders that aren't special, for example WEB-INF then you'll see it there.

like image 65
Walery Strauch Avatar answered Sep 19 '22 08:09

Walery Strauch


they actually aren't empty if you look at the directory out side of your editor (looks like eclipse). eclipse has created source folders for you which can be seen above. src/main/java and src/test/java.

so if you take a look at the folder in your operating systems explorer you should see files in there

like image 23
Connr Avatar answered Sep 21 '22 08:09

Connr