Maven-基于依赖关系导出类路径,没有.m2开销

时间:2019-03-19 16:17:00

标签: maven classpath

下面底部的pom代码创建一个类路径文件,其中包含相对于.m2 maven缓存的所有jar文件:

${M2_REPO}\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;${M2_REPO}\com\github\jnr\jnr-ffi\2.1.7\jnr-ffi-2.1.7.jar;...

将所有依赖项整齐地复制到target / lib

${project.build.directory}/lib

我想知道如何让maven使用我的target / lib目录的路径而不是maven缓存来创建类路径:

target/libslf4j-api-1.7.25.jar:target/lib/jnr-ffi-2.1.7.jar:...

Iam使用以下Maven代码:

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.0.1</version>
    <executions>
      <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals>
          <goal>copy-dependencies</goal>
        </goals>
        <configuration>
          <outputDirectory>${project.build.directory}/lib</outputDirectory>
          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>false</overWriteSnapshots>
          <overWriteIfNewer>true</overWriteIfNewer>
        </configuration>
      </execution>
      <execution>
        <id>build-classpath</id>
        <phase>package</phase>
        <goals>
          <goal>build-classpath</goal>
        </goals>
        <configuration>
          <attach>true</attach>
          <outputFile>${project.build.directory}/classpath</outputFile>
        </configuration>
      </execution>
    </executions>
    </plugin>

1 个答案:

答案 0 :(得分:0)

以下内容为我完成了工作:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>3.0.1</version>
    <executions>
      <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals>
          <goal>copy-dependencies</goal>
        </goals>
        <configuration>
          <outputDirectory>${project.build.directory}${file.separator}lib</outputDirectory>
          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>false</overWriteSnapshots>
          <overWriteIfNewer>true</overWriteIfNewer>
        </configuration>
      </execution>
      <execution>
        <id>build-classpath</id>
        <phase>package</phase>
        <goals>
          <goal>build-classpath</goal>
        </goals>
        <configuration>
          <attach>true</attach>
          <outputFile>${project.build.directory}${file.separator}classpath</outputFile>
          <prefix>target${file.separator}lib</prefix>
        </configuration>
      </execution>
    </executions>
  </plugin>