我的java程序被打包在一个jar文件中,并使用了一个外部jar库,bouncy castle。我的代码编译良好,但运行jar会导致以下错误:
java.lang.SecurityException: Manifest主属性的签名文件摘要无效
我在谷歌上搜索了一个多小时,想要找到一个解释,但几乎没有什么价值。如果有人看到这个错误之前,可以提供一些帮助,我将不胜感激。
我的java程序被打包在一个jar文件中,并使用了一个外部jar库,bouncy castle。我的代码编译良好,但运行jar会导致以下错误:
java.lang.SecurityException: Manifest主属性的签名文件摘要无效
我在谷歌上搜索了一个多小时,想要找到一个解释,但几乎没有什么价值。如果有人看到这个错误之前,可以提供一些帮助,我将不胜感激。
当前回答
如果您在尝试为Xamarin绑定JAR文件时遇到这种情况。Android绑定项目如下:
J2XA006:在反映清单主属性的com.your.class:无效签名文件摘要时引发了缺少类错误
只需使用Winzip打开JAR文件并删除meta-inf目录。重建-工作完成
其他回答
我也遇到过类似的问题。原因是我使用的JDK的JRE与Windows系统中的默认JRE不同。
使用正确的java.exe解决了我的问题。
I've recently started using IntelliJ on my projects. However, some of my colleagues still use Eclipse on the same projects. Today, I've got the very same error after executing the jar-file created by my IntelliJ. While all the solutions in here talking about almost the same thing, none of them worked for me easily (possibly because I don't use ANT, maven build gave me other errors which referred me to http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException, and also I couldn't figure out what are the signed jars by myself!)
最后,这帮助了我
zip -d demoSampler.jar 'META-INF/*.SF' 'META-INF/*.RSA' 'META-INF/*SF'
猜猜我的jar文件里删除了什么!
deleting: META-INF/ECLIPSE_.SF
deleting: META-INF/ECLIPSE_.RSA
这个问题似乎与一些与eclipse相关的文件有关。
请使用以下命令
zip -d yourjar.jar 'META-INF/*.SF' 'META-INF/*.RSA' 'META-INF/*.DSA'
如果您正在寻找一个不解包或修改原始库,而是使用一个特殊的JAR类加载器的Fat JAR解决方案,请参阅我这里的项目。
免责声明:代码不是我写的,只是打包并发布在Maven Central上,并在我的阅读中描述如何使用它。
我个人使用它来创建包含BouncyCastle依赖的可运行的优jar。也许它对你也有用。
对于使用kotlin脚本(kts)作为构建脚本的人:
task("fatJar", type = Jar::class) {
baseName = "${project.name}-fat"
manifest {
attributes["Implementation-Title"] = "Watcher Jar File"
attributes["Implementation-Version"] = version
attributes["Main-Class"] = "MainKt"
}
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) {
exclude(listOf("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA"))
}
with(tasks.jar.get() as CopySpec)
}