Home > Java > javaTutorial > How to include runtime dependencies in the target/lib folder with Maven?

How to include runtime dependencies in the target/lib folder with Maven?

Mary-Kate Olsen
Release: 2024-11-11 19:25:02
Original
517 people have browsed it

How to include runtime dependencies in the target/lib folder with Maven?

Including Runtime Dependencies in Target/Lib Folder with Maven

When building a project with Maven, it's often desirable to include the runtime dependencies in the target/lib folder. By default, the target folder only contains the project's JAR.

To resolve this issue, we can utilize the Maven Dependency Plugin. Here's a solution:

Maven Configuration:

To copy the runtime dependencies into the target/lib folder, modify your Maven configuration to include the following:

<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

Explanation:

  • We configure a with the ID 'qa'. This profile can be activated when needed.
  • Within the profile, we define a plugin execution for the Maven Dependency Plugin.
  • The copy-dependencies goal copies the project's dependencies during the install phase.
  • We specify the outputDirectory as target/lib, which is where the runtime dependencies will be copied to.

Usage:

To activate the 'qa' profile and copy the dependencies, execute the following command:

mvn clean install -Pqa
Copy after login

This process will ensure that the target/lib folder contains the project's runtime dependencies after the build.

The above is the detailed content of How to include runtime dependencies in the target/lib folder 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