Home > Java > javaTutorial > How to Copy Runtime Dependencies into Target/lib Using Maven?

How to Copy Runtime Dependencies into Target/lib Using Maven?

DDD
Release: 2024-11-25 09:14:10
Original
370 people have browsed it

How to Copy Runtime Dependencies into Target/lib Using Maven?

Copying Dependencies into Target/lib Using Maven

When attempting to copy runtime dependencies into the target/lib folder, Maven users may encounter a scenario where only the project's JAR is present after running mvn clean install.

To resolve this issue and ensure the inclusion of runtime dependencies, you can leverage the following approach:

Maven Dependency Plugin

The Maven Dependency Plugin provides a reliable solution for this task. By incorporating the following configuration, you can instruct Maven to copy the dependencies into the desired target/lib directory:

<project>
  ...
  <profiles>
    <profile>
      <id>qa</id>
      <build>
        <plugins>
          <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>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
Copy after login

Implementation

In the above configuration:

  • The maven-dependency-plugin is employed.
  • The qa profile is defined.
  • A plugin execution is triggered during the install phase.
  • The copy-dependencies goal is specified to execute the dependency copying task.
  • The outputDirectory element defines the target location for the copied dependencies.

By integrating this configuration into your Maven project, you can successfully have your project's runtime dependencies copied into the target/lib folder after performing a mvn clean install.

The above is the detailed content of How to Copy Runtime Dependencies into Target/lib Using 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template