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

How to Copy Dependencies to target/lib with Maven?

Susan Sarandon
Release: 2024-11-20 13:31:17
Original
877 people have browsed it

How to Copy Dependencies to target/lib with Maven?

Copying Dependencies to target/lib with Maven

Maven is a widely used build tool in Java projects. It manages dependencies and automates various build tasks. One common requirement in Java projects is to copy the runtime dependencies into a specific location within the build artifacts, typically target/lib for packaging purposes.

Solution

To achieve this in Maven, you can leverage the maven-dependency-plugin. Here's a configuration example:

<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

By adding this configuration to your Maven project, you can specify the target directory (target/lib in this case) where the runtime dependencies should be copied during the install phase. This will ensure that the JAR files of the dependencies are included along with your project's JAR when you execute mvn clean install.

The above is the detailed content of How to 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