Home > Java > javaTutorial > How to Automatically Copy Dependencies to target/lib with Maven?

How to Automatically Copy Dependencies to target/lib with Maven?

Linda Hamilton
Release: 2024-11-09 18:59:02
Original
761 people have browsed it

How to Automatically Copy Dependencies to target/lib with Maven?

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template