我希望 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(使用前将#替换为@)