Maven zip uber-jar和shell脚本 [英] maven zip uber-jar and shell script

查看:103
本文介绍了Maven zip uber-jar和shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望Maven结合使用由shade-plugin创建的uber-jar和all_files目录中的shell脚本.

I would like maven to combine an uber-jar created by the shade-plugin and a shell script from the all_files directory.

项目结构如下:

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文件来执行项目.

The jar is produced by projectB's pom file and then placed into the outtermost folder to be ready to be zipped with the shell script. The reason is so that the shell script can call the jar file to execute the project.

我希望其他程序员能够轻松解压缩文件并运行shell脚本而不必担心.而且我还需要Maven将脚本和jar打包在一起.我不确定到底如何在阴影插件中实现它.

I want other programmers to be able to easily unzip the file and run the shell script without worry. And I also need to have maven package the script and jar together. I'm not sure exactly how to implement that within the shaded plugin.

注意:我不想使用Assembly-Plug,因为它不能很好地打包依赖的jar.

Note: I do not want to use assembly-plugin because it doesn't package dependent jars well.

<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.

You don't want to use the maven-assembly-plugin for creating the uber-jar. But you will want to use it to create that ZIP.

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

Currently, your maven-shade-plugin is bound to the package phase. You could shift that execution to the prepare-package phase (since it actually prepares your final packaging) add an execution of the maven-assembly-plugin bound to the package phase. Your assembly would create a ZIP based on the shaded JAR (which will exist since the shade plugin will have been executed) and the shell script.

一个示例描述符如下:

<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>

根据 查看全文

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆