I'm starting to read about spring framework, where in the course they use maven and there are already things that I don't understand, some of which have nothing to do with spring or maven, but more with java.
Well, the first thing is, does maven, when adding a dependency to the pom.xml file, automatically download the library (the classes) to my project?
The second question comes with this image:
Why, when making a project with Spring or maven, do I get so many folders that don't have any content? (Ex: src-target)
The answer to the first question is yes, maven takes care of downloading the libraries that you declare as a dependency for your project only if these libraries are located in one of the maven central repositories (see section Approved Repository Hosting) . But maven does much more than this. Maven also allows you to download the sources and documentation for those projects (if they are available). Likewise, Maven will also download the dependencies of the libraries 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 its pom.xml file ), if Maven detects that you don't have that library installed locally, then it will download it for you.
In a bit of detail, when you declare a dependency in Maven, it will do the following:
<carpeta de usuario>/.m2
. On Windows it would beC:\Users\<tu usuario>\.m2
. On Mac it would be/Users/<tu usuario>/.m2
, and so on.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 settings you can make in Maven. For example, if your project is of type jar, Maven by default will not add any dependencies in the generated jar. However, if your project is of type war, Maven will by default add the dependencies inside the WEB-INF/lib (Java web application standard) folder.
The second question is answered and well detailed in Maven's Directory Design Standard Introduction . Anyway, here I provide a detail for the folders you have in your project according to the image you have shown:
mvn -Dmaven.test.skip=true
.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:
Note that
<build>
and<dependencies>
are two separate sections.Yes, that is exactly what it does.
The directory
/target
is where the files are created when you do the build!Here is a list of directories created by Maven, specifying what they are for:
https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html