线程“main”中的异常 java.lang.SecurityException:Manifest 主要属性的签名文件摘要无效
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22566191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
提问by Jay
Exception in thread "main" java.lang.SecurityException: Invalid signature file d igest for Manifest main attributes
at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVeri fier.java:240)
at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier .java:193)
at java.util.jar.JarVerifier.processEntry(JarVerifier.java:262)
at java.util.jar.JarVerifier.update(JarVerifier.java:216)
at java.util.jar.JarFile.initializeVerifier(JarFile.java:341)
at java.util.jar.JarFile.getInputStream(JarFile.java:406)
at sun.misc.URLClassPath$JarLoader.getInputStream(URLClassPath.java:75 2)
at sun.misc.Resource.cachedInputStream(Resource.java:77)
at sun.misc.Resource.getByteBuffer(Resource.java:160)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:436)
at java.net.URLClassLoader.access0(URLClassLoader.java:71)
at java.net.URLClassLoader.run(URLClassLoader.java:361)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:480)
Hi i am getting this error and i was wondering if anybody could tell me what was causing this.This is the snapshot of pox file of my project. Any help would be appreciated.
嗨,我收到此错误,我想知道是否有人可以告诉我是什么原因造成的。这是我项目的 pox 文件的快照。任何帮助,将不胜感激。
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.50</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.29</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1101-jdbc41</version>
</dependency>
<dependency>
<groupId>org.objectweb.joram</groupId>
<artifactId>jftp</artifactId>
<version>1.52</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>junit:junit</exclude>
<exclude>org.apache.maven:lib:tests</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
回答by Jay
I think i got the solution for my own question, addition of tags mentioned below to the pom.xml
solves the issue:
我想我得到了我自己问题的解决方案,添加了下面提到的标签来pom.xml
解决这个问题:
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>junit:junit</exclude>
<exclude>org.apache.maven:lib:tests</exclude>
</excludes>
http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Signed_JAR_File
http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Signed_JAR_File
回答by Athar
I was having similar issues, I added Bounty Castle dependency that was causing this error. Just removed it and after that it worked okay.
我遇到了类似的问题,我添加了导致此错误的 Bounty Castle 依赖项。刚刚删除它,之后它工作正常。
回答by jmsimpson68
The following Stackexchange question and answer worked for me. It uses a filter instead of and artifactSet exclude. I have tried the solutions in the above answer and it didn't work.
以下 Stackexchange 问答对我有用。它使用过滤器代替和 artifactSet 排除。我已经尝试了上述答案中的解决方案,但没有奏效。
回答by tharindu_DG
I was trying to create an uber jar with maven and ran in to this problem and I was able to solve the issue as follows.
我试图用 maven 创建一个 uber jar 并遇到了这个问题,我能够按如下方式解决这个问题。
Here is how I configured the shade
plugin to include twitter4j
to my uber jar.
这是我如何配置shade
插件以包含twitter4j
到我的 uber jar 中。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>spark-streaming-twitter_2.10:spark-streaming-twitter_2.10</artifact>
<includes>
<include>**</include>
</includes>
</filter>
<filter>
<artifact>twitter4j-stream:twitter4j-stream</artifact>
<includes>
<include>**</include>
</includes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
Hope this helps.
希望这可以帮助。
回答by 0_o
After surfing the internet for hours, and still unable to find the solution, I stumbled upon this command which solved my problem:
在网上冲浪几个小时后,仍然无法找到解决方案,我偶然发现了这个解决我问题的命令:
zip -d yourjar.jar 'META-INF/.SF' 'META-INF/.RSA' 'META-INF/*SF'
This command rips off the signature files for the previous jars, and then once you sign it you'l find no error.
这个命令会撕掉之前 jars 的签名文件,然后一旦你签名,你就会发现没有错误。
回答by Manuel Sopena Ballesteros
This error means that maven shade plugin has modified one of your dependencies hence the signature for those libraries are invalid.
此错误意味着 maven shade 插件已修改您的依赖项之一,因此这些库的签名无效。
remove the signature files is a work around and a solution depending on your use case. For me it is a bad practice so I ended up replacing the maven shade plugin for Apache Maven Assembly Plugin to create the jar with the dependencies and seems to work https://maven.apache.org/plugins/maven-assembly-plugin/
删除签名文件是一种变通方法和解决方案,具体取决于您的用例。对我来说,这是一个不好的做法,所以我最终替换了 Apache Maven Assembly Plugin 的 maven shade 插件以创建具有依赖项的 jar,并且似乎可以正常工作https://maven.apache.org/plugins/maven-assembly-plugin/
example:
例子:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
your.class.with.main.method
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
build your jar with dependencies included:
构建包含依赖项的 jar:
mvn package