Hello Stackoverflow社区,
当尝试编译使用bouncycastle安全提供程序的Maven项目时,出现以下错误:java.lang.SecurityException: JCE cannot authenticate the provider BC
我知道必须对该jar进行签名,所以我已将其添加到pom.xml中以防止编译错误:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>
package
</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
基于此(bouncycastle provider can't find classes needed for algorithm),我添加了以下内容:Security.setProperty("java.policy", "unlimited");
,并添加了具有以下内容的提供者:Security.addProvider(new BouncyCastleProvider());
在我的公共static void main中。
不幸的是,这没有用。您是否对如何实现上面链接中显示的内容有任何建议,而不必分别为每个JRE实现它?预先感谢您的帮助。
答案 0 :(得分:0)
我从以下问题中找到了带有可执行打包程序maven插件(https://github.com/nthuemmel/executable-packer-maven-plugin)的解决方案:How do I put all required JAR files in a library folder inside the final JAR file with Maven?
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>de.ntcomputer</groupId>
<artifactId>executable-packer-maven-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<mainClass>mh.cryptomail.CryptoMail</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>pack-executable-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>mh.cryptomail.CryptoMail</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
它将所有jar拷贝到未修改的结果jar中,但是由于它必须注册一个自定义的类加载器,因此在启动时会花费更长的时间(约15秒)。