因为BouncyCastle jar被签名并且在maven-assembly-plugin中使用jar-with-dependencies会破坏这些签名,我想知道是否有可能创建这种输出:
-
我的代码和胖 jar 中的每个依赖项,但不包括BC jar
-
lib /子文件夹中的BC jar
我设法使用看起来像这样的程序集文件在我的胖 jar 中排除BC jar:
<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>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<unpack>true</unpack>
<excludes>
<exclude>org.bouncycastle:bcprov-jdk15on</exclude>
</excludes>
</dependencySet>
</dependencySets>
现在,我如何告诉maven-assembly-plugin将BC jar作为独立jar放在lib /文件夹中,但仍然在manifest文件中引用它?
最好的祝福 .
编辑:我试图做以下(不是我想要的干净,但如果它可以工作,这就足够了):
我从程序集中排除了BC jar,并在maven-assembly-plugin的maven archiver部分添加了一个自定义类路径注入:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/jar.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>${mainClass}</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Class-Path>lib/bcprov-jdk15on.jar</Class-Path>
</manifestEntries>
</archive>
<outputDirectory>${staging.dir}</outputDirectory>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
清单文件按预期修改:
Manifest-Version: 1.0
Implementation-Title: MyCode
Implementation-Version: 2.0.27.3
Built-By: ixo
Implementation-Vendor-Id: my.package
Class-Path: lib/bcprov-jdk15on.jar
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_144
Implementation-Vendor: foo
Main-Class: my.package.Main
但是jvm似乎没有考虑类路径入口,我不明白为什么
编辑2:好的,我发现为什么以前的编辑不起作用,maven-assembly-plugin生成index.list文件,如果这个文件存在,则使用它而不是manifest.mf,因为我添加了BC jar通过覆盖maven-archiver部分中的类路径,index.list是错误的 . 如果使用胖jar生成,则禁用索引不起作用 .
1 回答
好的,所以这是我真正肮脏的解决方案,我对此并不感到自豪,如果有人能发布一个更好的解决方案,很乐意向他投票 .
以下是制作带有BC jar 的脂肪 jar 的步骤:
创建一个汇编文件,排除您想要的任何BC依赖项
<exclude>org.bouncycastle:bcprov-jdk15on</exclude>
使用maven归档程序在manifest.mf文件中附加自定义类路径条目
<manifestEntries><Class-Path>lib/bcprov-jdk15on-1.57.jar</Class-Path></manifestEntries>
使用truezip-maven-plugin从fat jar中删除index.list文件
它完成了 .