Automatically Copying Dependencies to target/lib with Maven
When running mvn clean install, the target folder usually only contains the project's JAR file, excluding runtime dependencies. To address this, the maven-dependency-plugin can be configured to copy these dependencies into the desired directory.
Solution:
Implement the following configuration within the project's POM.xml file:
<plugin> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <phase>install</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> </configuration> </execution> </executions> </plugin>
This configuration directs the copy-dependencies goal to run during the install phase. The outputDirectory parameter specifies the destination path for the copied dependencies, which in this case is the target/lib folder.
By adding this configuration, the mvn clean install command will now copy all runtime dependencies into the target/lib folder, ensuring their availability for deployment or further processing.
The above is the detailed content of How to Automatically Copy Dependencies to target/lib with Maven?. For more information, please follow other related articles on the PHP Chinese website!