“Invalid signature file” when attempting to run a .jar

后端 未结 21 2017
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 05:34

My java program is packaged in a jar file and makes use of an external jar library, bouncy castle. My code compiles fine, but running the jar leads to the following error:

相关标签:
21条回答
  • 2020-11-22 06:04

    The solution listed here might provide a pointer.

    Invalid signature file digest for Manifest main attributes

    Bottom line :

    It's probably best to keep the official jar as is and just add it as a dependency in the manifest file for your application jar file.

    0 讨论(0)
  • 2020-11-22 06:05

    If you are looking for a Fat JAR solution without unpacking or tampering with the original libraries but with a special JAR classloader, take a look at my project here.

    Disclaimer: I did not write the code, just package it and publish it on Maven Central and describe in my read-me how to use it.

    I personally use it for creating runnable uber JARs containing BouncyCastle dependencies. Maybe it is useful for you, too.

    0 讨论(0)
  • 2020-11-22 06:05

    I had a similar problem. The reason was that I was compiling using a JDK with a different JRE than the default one in my Windows box.

    Using the correct java.exe solved my problem.

    0 讨论(0)
  • 2020-11-22 06:06

    This happened to me in Intellij when I clicked "Add as a Maven Project" on bottom line when Intellij said "non-managed pom files found.". Meanwhile out folder was already generated. So it did not get recent changes.

    Deleting out folder and running the program solved the issue for me. out folder was then recreated.

    See the answer of Little Fox as well. The error I received was very similar to his.

    0 讨论(0)
  • 2020-11-22 06:07

    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!)

    Finally, this helped me

    zip -d demoSampler.jar 'META-INF/*.SF' 'META-INF/*.RSA' 'META-INF/*SF'
    

    Guess what's been removed from my jar file?!

    deleting: META-INF/ECLIPSE_.SF 
    deleting: META-INF/ECLIPSE_.RSA
    

    It seems that the issue was relevant to some eclipse-relevant files.

    0 讨论(0)
  • 2020-11-22 06:10

    I had the same issue in gradle when creating a fat Jar, updating the build.gradle file with an exclude line corrected the issue.

    jar {
        from {
            configurations.compile.collect {
                it.isDirectory() ? it : zipTree(it)
            }
        }
        exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
        manifest {
            attributes 'Main-Class': 'com.test.Main'
        }
    }
    
    0 讨论(0)
提交回复
热议问题