MAVEN's non-web projects need to refer to a lot of jar packages at execution time, which is usually done by unifying these jar packages into the Lib directory, and Maven's dependency plugin can do this for us.
We need to add a plugin,plugin content within the plugins node of the build node of the Pom file as follows:
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artif Actid>maven-dependency-plugin</artifactid> <executions> <execution> <id>copy-dependencies</id> <phase>prepare- Package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputdirectory>${project .build.directory}/lib</outputdirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> </configuration> </execution> </exec utions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> &L T;mainclass>themainclass</mainclass> </manifest> </archive> </configuration> </plugin></plugin>
In the above configuration we used the Maven-dependency-plugin plug-in, and then performed the (execution node) copy-dependencies operation. The output directory that we specify is: ${project.build.directory}/lib, where ${project.build.directory} is the target directory we usually see, That is to copy the jar to the Lib directory under the target directory.
How to copy a jar package referenced in a MAVEN project into a Lib folder