【发布时间】:2018-02-20 20:40:23
【问题描述】:
因为 BouncyCastle jar 已签名并且在 maven-assembly-plugin 中使用 jar-with-dependencies 会破坏这些签名,所以我想知道是否可以创建这种输出:
- 我的代码和一个 fat jar 中的每个依赖项,但不包括 BC jar
- lib/ 子文件夹中的 BC jar
我设法使用如下所示的程序集文件将 BC jar 排除在我的 fat 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/ 文件夹中,但仍然在清单文件中引用它?
最好的问候。
编辑: 我尝试执行以下操作(不像我想要的那样干净,但如果它可以工作,那就足够了):
我从程序集中排除了 BC jar,并在 maven-assembly-plugin 的 maven 归档器部分添加了自定义类路径注入:
<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 生成,禁用索引不起作用。
【问题讨论】:
-
你不能从 java 中的 jar 中引用 jar。
-
是的,我知道,我希望 BC 罐在肥罐外面。
-
你为什么不直接运行你的代码,比如 java -cp xx.jar:/lib/BC.jar ....main stackoverflow.com/questions/18413014/…
-
因为我无法更改代码的运行方式。
标签: java maven bouncycastle maven-assembly-plugin