【问题标题】:Create a zip with all dependencies with Maven [duplicate]使用 Maven 创建一个包含所有依赖项的 zip [重复]
【发布时间】:2011-04-19 13:33:06
【问题描述】:

可能重复:
With Maven, how can I build a distributable that has my project's jar and all of the dependent jars?

也许我是盲人,但是 maven 程序集插件可以只创建一个包含当前 project.jar 和我所有依赖项 jar 的 zip 文件吗? “bin” id 只包含我的 project.jar 和 jar-with-dependencies 放在一个我不喜欢的 jar 中。

【问题讨论】:

    标签: maven maven-assembly-plugin


    【解决方案1】:

    您需要一个自定义程序集描述符来执行您想要的操作。它是 bin 和 jar-with-dependencies 预定义描述符的组合。在src/main/assembly 文件夹中创建了一个名为assembly.xml 的自定义程序集描述符。

    这是一个基本上是添加了依赖集的 bin 描述符的示例:

        <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
      <id>bin</id>
      <formats>
        <format>tar.gz</format>
        <format>tar.bz2</format>
        <format>zip</format>
      </formats>
      <fileSets>
        <fileSet>
          <directory>${project.basedir}</directory>
          <outputDirectory>/</outputDirectory>
          <includes>
            <include>README*</include>
            <include>LICENSE*</include>
            <include>NOTICE*</include>
          </includes>
        </fileSet>
        <fileSet>
          <directory>${project.build.directory}/site</directory>
          <outputDirectory>docs</outputDirectory>
        </fileSet>
      </fileSets>
      <dependencySets>
        <dependencySet>
          <outputDirectory>/</outputDirectory>
          <useProjectArtifact>true</useProjectArtifact>
          <scope>runtime</scope>
        </dependencySet>
      </dependencySets>
    </assembly>
    

    然后更改您的 pom 以使用描述符而不是 descriptorRef 来告诉它您的自定义描述符在哪里。

    <project>
      [...]
      <build>
        [...]
        <plugins>
          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2.1</version>
            <configuration>
              <descriptors>
                <descriptor>src/main/assembly/assembly.xml</descriptor>
              </descriptors>
            </configuration>
            [...]
    </project>
    

    【讨论】:

    • 这就是它的工作原理,谢谢。与第一篇类似。
    【解决方案2】:

    看看hereExample 502...有一个示例如何将所有依赖项等打包成tar.gz/zip等。

    【讨论】:

      【解决方案3】:

      看看fat-jar插件。

      【讨论】:

        猜你喜欢
        • 2011-04-12
        • 1970-01-01
        • 2017-06-14
        • 2021-12-25
        • 1970-01-01
        • 2014-06-08
        • 2014-01-08
        • 1970-01-01
        • 2019-11-02
        相关资源
        最近更新 更多