maven zip uber-jar 和 shell 脚本

2024-04-10

我希望 Maven 能够将由 shade-plugin 创建的 uber-jar 和 all_files 目录中的 shell 脚本结合起来。

项目结构如下所示:

all_files/
    mvn_script.sh
    projB-shaded.jar

    maven_project/
        guide/
            parent-pom.xml
        projA/
            pom.xml
        projB/
            pom.xml

jar 由projectB 的pom 文件生成,然后放入最外面的文件夹中,准备与shell 脚本一起压缩。原因是为了让shell脚本可以调用jar文件来执行项目。

我希望其他程序员能够轻松解压该文件并无忧无虑地运行 shell 脚本。而且我还需要让maven将脚本和jar打包在一起。我不确定如何在阴影插件中实现它。

注意:我不想使用 assembly-plugin,因为它不能很好地打包依赖的 jar。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.4.3</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <minimizeJar>true</minimizeJar>
          <outputFile>../../guide/${project.artifactId}-${project.version}-shaded.jar</outputFile>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <manifestEntries>
                <Main-Class>projB.classB</Main-Class>
              </manifestEntries>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>                    

你不想使用maven-assembly-plugin用于创建 uber-jar。但您将需要使用它来创建该 ZIP。

目前,您的maven-shade-plugin绑定到package阶段。您可以将该执行转移到prepare-package阶段(因为它实际上准备了您的最终包装)添加执行maven-assembly-plugin绑定到package阶段。您的程序集将基于阴影 JAR(由于执行阴影插件而存在)和 shell 脚本创建一个 ZIP。

示例描述符如下:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
    <id>your-id</id>
    <formats>
        <format>zip</format>
    </formats>
    <files>
        <file>
            <source>${project.build.directory}/projB-shaded.jar</source>
            <outputDirectory>/</outputDirectory>
        </file>
        <file>
            <source>/path/to/mvn_script.sh</source>
            <outputDirectory>/</outputDirectory>
        </file>
    </files>
</assembly>

具有以下 POM 配置:

<plugin>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.4.3</version>
    <executions>
        <execution>
            <phase>prepare-package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <!-- current configuration -->
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.6</version>
    <executions>
        <execution>
            <id>assemble</id>
            <goals>
                <goal>single</goal>
            </goals>
            <phase>package</phase>
            <configuration>
                <descriptors>
                    <descriptor>/path/to/assembly.xml</descriptor>
                </descriptors>
            </configuration>
        </execution>
    </executions>
</plugin>

程序集描述符的典型位置位于src/assembly根据Maven 标准目录布局 https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

maven zip uber-jar 和 shell 脚本 的相关文章

随机推荐

  • CryptoJS.enc.Base64.stringify() 和普通 Base64 加密的区别

    我正在尝试将以下哈希加密为 Base64 6bb984727b8c8c8017207e54b63976dc42ea9d24ad33bd5feeaa66869b650096 需要访问网站的API 该网站显示了一个 JavaScript 示例脚
  • ES6中使用map函数更新对象的属性值

    我正在尝试用 ES6 编写这个代码 以下是我想要实现的目标 假设我有一个名为的对象数组schools let schools name YorkTown country Spain name Stanford country USA nam
  • Chrome 扩展内容脚本能否对本身属于 Chrome 扩展的一部分的 html 文件发出 jQuery AJAX 请求?

    我正在开发 Chrome 扩展程序内容脚本 https developer chrome com extensions content scripts这将在特定页面上向页面注入附加内容 以向现有站点添加功能 我的 Chrome 扩展程序中有
  • Swift 4 中键值编码的优势

    我只是想知道 Swift 4 中键值编码的好处 因为我很了解键值编码 保留对属性的引用 而不实际访问属性所持有的基础数据 例如 struct Student var name String var rollNo String let stu
  • 从 R 中单列中的所有数据中删除前缀

    我会有一个列 其中的数据如下所示 M999 00001 M999 00002 有没有办法删除R中列中的所有 M 我们可以用sub df1 1 lt sub df1 1 Or use substring substring df1 1 2 d
  • 将多个字符列更改为日期

    我有多个字符列 大约 20 个 我想将它们全部更改为日期格式并使用 r 删除时间 我试过了loops mutate and apply 这是仅使用两列的一些示例数据 col1 c 2017 04 01 23 00 00 2017 03 03
  • 从字符串解方程得到 C 的结果

    我想知道是否有人有关于如何做一些听起来很简单但在尝试编程时看起来并不像的事情的信息或经验 这个想法是 给出一个包含方程的字符串 例如 2 x 10 这很简单 但它可能会变得非常复杂 例如 sqrt 54 35 x 2 等等on 程序将返回
  • Count() 和左连接问题

    我在查询时遇到问题 该查询显示商店列表以及与其关联的产品数量 我已经玩左连接等有一段时间了 但没有成功 这些表具有以下结构 商店表包含列 id name 产品表包含列 id name status shop 查询如下 select s na
  • 在 Angular 2 中使用普通 js 代码 (angular-cli)

    我正在努力实施Vanilla Tilt JS 插件 https micku7zu github io vanilla tilt js 在我的项目中 但我什至似乎找不到在我的项目中使用 vanilla js 导入的方法 到目前为止 我已经尝试
  • Windows 7 家庭高级版上的 Visual Studio 2008/2010 和 SQL Server 2008

    在 Windows 7 Home Premium 上使用 VS 2008 2010 和 SQL Server 2008 开发 ASP NET 和 WPF 应用程序是否有任何限制 我知道您可以在 Home Premium 上运行 IIS 7
  • 从程序集文件加载的类型不等于在 .NET Core 中引用时的同一类型

    我拿一个Type 查询其程序集位置 然后从同一地址加载该程序集 并从加载的程序集中查找相同类型的程序集 结果类型不等于原始类型 这是测试用例 TestMethod public void TestTypeLoadingWithFilePat
  • 如何将整数数组划分为偶数和奇数?

    我想对数组进行分区 例如 1 2 3 4 5 6 7 8 第一个分区应保留偶数值 第二个分区应保留奇数值 结果示例 2 4 6 8 1 3 5 7 我设法用内置解决了这个问题两次Array prototype方法 第一个解决方案使用map
  • 根据一列中的不同值获取行

    如何通过不同的值获取行COL2 例如 我有下面的数据框 COL1 COL2 a com 22 b com 45 c com 34 e com 45 f com 56 g com 22 h com 45 我想根据中的唯一值获取行COL2 CO
  • 我需要采取哪些步骤来向我的 blogger/blogspot 博客添加良好的 Java 代码格式? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我正在寻找一系列步骤来将 java 代码格式添加到我的 blogspot 博客 我真的在寻找一个傻瓜指
  • 使用 Firebase 和 S3

    我正在使用 firebase 和 ionic Angular JS 创建一个应用程序 我想知道是否可以使用 amazon s3 来托管照片 并将 url 来自 s3 存储在 firebase 中 并将其提供给用户 我想这样做 因为 fire
  • JavaScript 排序函数如何工作(作为一种算法)? [复制]

    这个问题在这里已经有答案了 JavaScript带参数的排序函数 http www javascriptkit com javatutors arraysort shtml允许传入一个函数 例如 var myarray 25 8 7 41
  • 如何在 Lucene 6 中对数字字段进行排序

    我想根据数字字段对搜索结果进行排序 在下面的示例代码中 我想根据 年龄 字段进行排序 我从使用以下答案开始 如何在 Lucene 6 中对 IntPont 或 LongPoint 字段进行排序 https stackoverflow com
  • 修改framework.jar中的java代码

    我手机上的库存 ROM 与 MVNO 移动虚拟网络运营商 存在问题 基本上这意味着我的数据连接仅在漫游时有效 这是一个已知问题 已在多个 ROM 上得到修复 但我的尚未修复 为了解决这个问题 我想修改framework jar文件的源 sy
  • 如何在 Xcode 5 中重命名项目?

    如何在 Xcode 5 中重命名项目 我需要采取什么步骤 在过去 这始终是一个非常棘手的手动过程 嗯 答案在 Xcode 5 中非常非常简单 在左侧的项目导航器中 缓慢单击 2 次 项目文件名将可编辑 输入新名称 将出现一个带有警告的表 并
  • maven zip uber-jar 和 shell 脚本

    我希望 Maven 能够将由 shade plugin 创建的 uber jar 和 all files 目录中的 shell 脚本结合起来 项目结构如下所示 all files mvn script sh projB shaded jar