When compiling your project, Maven will download the corresponding .jar file from the repository, usually the central repository (you can configure different repositories, both for mirroring and for your own libraries that are not available in the central repositories).
If your IDE knows about Maven, it will analyze pom
and either load the dependencies themselves or ask Maven to do this. Then it will open the dependency banks, and you will get autocomplete: the IDE "imports" the banks behind the scenes.
The repository contains not only the .jar file for the dependency, but also the ".pom" file that describes its dependencies. Thus, maven will recursively load its dependencies, and you will get all the banks necessary to compile your software.
Then, when you try to run your software, you will need to tell the JVM where to find these dependencies (i.e. you have to put them in the class path).
What I usually do is copy the dependencies to the target/lib/
directory, so itβs easy to deploy the software and run it. To do this, you can use the maven-dependency-plugin
, which you specify in the <build>
:
<build> <plugin> <artifactId>maven-dependency-plugin</artifactId> <version>2.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> </configuration> </execution> </executions> </plugin> </build>
source share