Intellij打包jar文件, 在cmd执行jar文件时 java.lang.SecurityException: no manifest section for signature file entry
1.泄露一个小程序给老婆用, 封装了一下, 执行的时候报一下错误:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: no manifest section for signature file entry org/bouncycastle/jce/provider/JDKMessageDigest$RIPEMD256.class
at sun.security.util.SignatureFileVerifier.verifySection(Unknown Source)
at sun.security.util.SignatureFileVerifier.processImpl(Unknown Source)
at sun.security.util.SignatureFileVerifier.process(Unknown Source)
at java.util.jar.JarVerifier.processEntry(Unknown Source)
at java.util.jar.JarVerifier.update(Unknown Source)
at java.util.jar.JarFile.initializeVerifier(Unknown Source)
at java.util.jar.JarFile.getInputStream(Unknown Source)
at sun.misc.URLClassPath$JarLoader$2.getInputStream(Unknown Source)
at sun.misc.Resource.cachedInputStream(Unknown Source)
at sun.misc.Resource.getByteBuffer(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
请按任意键继续. . .
2.最后删除META-INF文件夹下*.SF,*.DSA 文件解决了 (压缩软件打开jar)
3.最后一劳永逸的解决, 在pom文件里面加上如下插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.empress.replication.main.Main</mainClass>
</transformer>
<!-- <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>-->
</transformers>
</configuration>
</execution>
</executions>
</plugin>
参考资料 :
1.Intellij打包jar文件,“java.lang.SecurityException: Invalid signature file digest for Manifest main attrib
https://blog.csdn.net/qq_25925973/article/details/53370501
2.maven生成可执行jar文件,排除其他jar中的SF,DSA,RSA等文件
https://blog.csdn.net/tian_shi_hei_de/article/details/78490392