因爲BouncyCastle jar被簽名,並且在maven-assembly-plugin中使用jar-with-dependencies會破壞這些簽名,我想知道是否有可能創建這種類型輸出:排除BouncyCastle jar但在fat fat jar中包含其他所有內容
- 我的代碼,並在脂肪罐子每個依賴性,但不包括BC罐子
- 在一個lib公元前JAR /子目錄
我設法排除在我的脂肪罐子BC罐子使用如下所示的彙編文件:
<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的組裝插件把BC罐子作爲獨立的罐子在一個lib /文件夾,但仍然在清單文件中引用呢?
此致敬禮。
編輯: 我試着做以下(不乾淨,因爲我想要的,但如果它可以工作,這將是足夠了):
我排除從組件的BC罐子,我添加在行家組裝-插件的行家存檔器部分的自定義類路徑注射:
<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,並且因爲我通過在maven-archiver部分中覆蓋類路徑來添加BC jar,那麼index.list是錯誤的。如果使用fat jar生成,禁用索引不起作用。
您不能從java中的jar中引用jar。 –
是的,我知道,我想讓BC罐子在肥缸外面。 –
爲什麼不直接運行你的代碼就像java -cp xx.jar:/lib/BC.jar .... main https://stackoverflow.com/questions/18413014/run-a-jar-file-from -THE-命令行和指定-類路徑 –