2017-09-12 82 views
0

因为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生成,禁用索引不起作用。

+0

您不能从java中的jar中引用jar。 –

+0

是的,我知道,我想让BC罐子在肥缸外面。 –

+0

为什么不直接运行你的代码就像java -cp xx.jar:/lib/BC.jar .... main https://stackoverflow.com/questions/18413014/run-a-jar-file-from -THE-命令行和指定-类路径 –

回答

0

好的,所以这里是我非常肮脏的解决方案,我不是很自豪,如果有人能发布更好的解决方案,我会很乐意提高他的解决方案。

下面是步骤,使与外界BC罐子(S)脂肪罐子:

  1. 创建排除任何BC依赖你想<exclude>org.bouncycastle:bcprov-jdk15on</exclude>
  2. 使用Maven存档附加自定义类的汇编文件在MANIFEST.MF文件-path项<manifestEntries><Class-Path>lib/bcprov-jdk15on-1.57.jar</Class-Path></manifestEntries>
  3. 使用truezip - Maven的插件从脂肪罐子

有删除文件INDEX.LIST我t完成了。

相关问题