Home  >  Article  >  Java  >  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
Mary-Kate OlsenOriginal
2024-11-11 19:25:02486browse

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>

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

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!

Statement:
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