maven - 使用 Maven 创建一个包含所有依赖项的 zip

标签 maven maven-assembly-plugin

这个问题在这里已经有了答案:




9年前关闭。




Possible Duplicate:
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 中。

最佳答案

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

这是一个示例,它基本上是添加了依赖项集的 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>

关于maven - 使用 Maven 创建一个包含所有依赖项的 zip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5717183/

相关文章:

maven - 错误: package javax. servlet不存在

java - 有没有通用的 Maven 代码生成器?

java - 如何将 jar 与 Maven Assembly Plugin 放在同一文件夹中

maven-2 - 如何在 Maven 中为输出 Artifact 加时间戳?

maven - 如何让 maven-assembly-plugin 尊重 pom.xml 中定义的排除项?

java - Maven - 使用父项目中的程序集文件和配置

java - Tomcat Server 7 的 Spring Maven Webapp 错误

maven - Kotlin-Kapt 注解处理器无法与 Maven 一起使用

java - Maven - 不要编译测试类中的特定测试方法

java - 我如何强制 Maven 将我的项目打包为 1.5?