【问题标题】:Maven package in-project repository dependencies inside jarMaven 将项目内存储库依赖项打包到 jar 中
【发布时间】:2017-04-06 06:23:47
【问题描述】:

我正在使用项目内存储库依赖项解决方案在我的 Maven 项目中包含第三方 jar 作为依赖项。我正在按照this blog 上的说明进行操作。

现在,我希望当我将 Maven 项目打包到 jar 中时,创建的 jar 应该有一个 lib 文件夹,其中包含第三方 jar。但是,我不希望将其他依赖项打包在 jar 中。 (我不想要一个包含所有依赖项的胖 jar,我只想要一个包含一个第三方依赖项 jar 的 jar)。

我一直在尝试使用 maven-dependency-plugin 和 maven-jar-plugin,但我无法实现我想要的。

有人可以帮帮我吗?

【问题讨论】:

    标签: java maven jar maven-dependency-plugin uberjar


    【解决方案1】:

    你可以使用maven-dependency-plugin(看here),如下图所示,这个插件将提供很多选项来包含ArtifactId(即<includeArtifactIds>)或groupId(<includeGroupIds>)等的jars...

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

    因此,上面的代码会将YOUR_THIRDPARTY_JAR_NAME.jar 添加到您最终的.jar 文件的lib 文件夹中

    【讨论】:

      【解决方案2】:

      看看Maven Assembly Plugin。它允许过滤包含的依赖项,因此您可以选择要包含在程序集中的依赖项

      【讨论】:

        猜你喜欢
        • 2011-04-03
        • 1970-01-01
        • 2012-11-01
        • 2018-12-19
        • 2019-09-03
        • 1970-01-01
        • 1970-01-01
        • 2023-03-30
        相关资源
        最近更新 更多