The answer to the first question is yes, maven is responsible for downloading the libraries that you declare as dependency for your project only if these libraries are in any of the maven central repositories (see section Approved Repository Hosting) . But maven does a lot more than this. Maven also allows you to download the sources and documentation of those projects (if they are available). Also, Maven will also download the dependencies of the bookstores that you indicate as a dependency. For example, Spring Core 4.2.5 depends on the commons-codec version 1.10 library (as shown in your pom.xml file ), if Maven detects that you do not have that library installed locally, then it will download it for you.
In detail, when you declare a dependency on Maven, you will do the following:
- Find if the library is in your local maven repository, usually located in
<carpeta de usuario>/.m2 . In Windows it would be
C:\Users\<tu usuario>\.m2 . On Mac it would be
/Users/<tu usuario>/.m2 , and so on.
- If it is not there, it will download the library from a central repository.
It should be noted that Maven will use the downloaded libraries to compile your project. This DOES NOT mean that your final artifact will contain the dependencies embedded in it. This depends on the type of project and some additional configurations that you can do in Maven. For example, if your project is a jar type, Maven by default will not add any dependency on the generated jar. However, if your project is a war type, Maven will by default add the dependencies within the WEB-INF / lib folder (Java web application standard).
The second question is answered and well detailed in Introduction to Standard Design of Maven Directories (link in English). Anyway, here I give a detail for the folders that you have in your project according to the image that you have shown:
- src: Folder for all sources and resources used in the project
- main: Sources and main resources of the project. By default, the elements located in this folder will be added to the generated artifact (jar, war, etc)
- java: Project sources. By default, the compiled Java files (.java) located here are added to the generated artifact. Any other type of file (eg xml) will be ignored. If there is a compilation error, the artifact will not be generated.
- resources: Project resources. Here reside the configuration files and other additional resources to be used in the project. For example: images (jgp, pgn), configuration files (properties, xml, json), templates (xlsx, docx, pdf), among others. By default, all files are stored directly in the generated artifact.
- test: Sources and resources used during the testing phase of the project. By default, Maven will NOT add these files to the generated artifact.
- java: Sources of project evidence. These sources will be compiled together with the sources located in src / main / java. These compilations are not added to the generated artifact. However, if there is a compilation error, the artifact will not be generated. To avoid this, you can indicate in your IDE that the testing phase is not used or from the command line use
mvn -Dmaven.test.skip=true .
- target: Contains all the elements generated after running Maven (mvn) on the project. This includes: files generated at compile time, compiled, final generated artifact (jar, war, etc)
Additionally, Maven by default will make your project use Java 5 (as shown in the image, your project uses Java 5 or J2SE 1.5). To avoid this and use your favorite version of Java (6, 7, 8, 9?) You must add a plugin under the build section in your pom.xml file:
<!-- En mi caso, declaro utilizar Java 8 en el proyecto -->
Keep in mind that
<dependencies> are two separate sections.