Maven 依赖插件复制带有依赖项的 jar

标签 maven jar maven-2 maven-3 maven-plugin

我正在尝试将一个 jar 从我的本地存储库复制到另一个项目中,如下所述:

http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html

但是,我的 jar 是作为“具有依赖项的 jar”从 maven-assembly-plugin 中出来的,它将常规 jar 和组装好的 jar 放在我的本地存储库中。 jar 名称类似于:

example-test-0.0.1-SNAPSHOT-jar-with-dependencies.jar

如果我手动复制,我可以在 repo 中找到它并使用它。我认为让 maven 复制它是个好主意,所以我使用了上面描述的依赖复制目标。

但是我无法让它工作,所以它复制了“具有依赖关系的 jar” jar。

这是 pom 的样子:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.10</version>
    <executions>
      <execution>
        <id>copy</id>
        <phase>package</phase>
        <goals>
          <goal>copy</goal>
        </goals>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>my.group</groupId>
              <artifactId>example-test</artifactId>
              <version>0.0.1-SNAPSHOT</version>
              <type>jar</type>
              <overWrite>true</overWrite>
              <outputDirectory>libs</outputDirectory>
              <destFileName>somename.jar</destFileName>
            </artifactItem>
          </artifactItems>

          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>true</overWriteSnapshots>
        </configuration>
      </execution>
    </executions>
  </plugin>

我试图将类型设置为“jar-with-dependencies”,但这没有用。只有当我让类型为“jar”时它才有效,但它会复制常规的未组装的 jar。任何想法如何解决这一问题?

最佳答案

如果您有这样的 Artifact :

example-test-0.0.1-SNAPSHOT-jar-with-dependencies.jar

你想像这样引用它:
        <artifactItem>
          <groupId>my.group</groupId>
          <artifactId>example-test</artifactId>
          <version>0.0.1-SNAPSHOT</version>
          <type>jar</type>
          <classifier>jar-with-dependencies</classifier>
          <overWrite>true</overWrite>
          <outputDirectory>libs</outputDirectory>
          <destFileName>somename.jar</destFileName>
        </artifactItem>

例子在这里:
        <artifactItem>
          <groupId>[ groupId ]</groupId>
          <artifactId>[ artifactId ]</artifactId>
          <version>[ version ]</version>
          <type>[ packaging ]</type>
  this---><classifier> [classifier - optional] </classifier>
          <overWrite>[ true or false ]</overWrite>
          <outputDirectory>[ output directory ]</outputDirectory>
          <destFileName>[ filename ]</destFileName>
        </artifactItem>

关于Maven 依赖插件复制带有依赖项的 jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28975230/

相关文章:

java - 从插件代码修改 POM 设置

javascript - 如何在 Maven 模块之间共享 JavaScript 代码

java - 子项目中的 WebApplicationInitializer

java - 在导出到 jar 文件的文件路径中使用加号 (+)

java - 使用 maven 构建后未找到 src/main/resources 中的资源

mysql - 在 $catalina_home/lib 中带有 mysql 驱动程序的 maven tomcat 插件

java - 在没有 Tomcat 管理器的情况下从 jenkins 自动部署 war 文件

java - 是否可以将 Ear 模块定义为多模块项目中的父模块?

java - 如何从 JAR 中访问图像

加载jar文件时找不到Java类