线程“main”中的异常java.lang.SecurityException:Manifest主要属性的签名文件摘要无效

时间:2016-12-17 08:57:20

标签: java eclipse gradle

创建了java gradle项目,我可以通过运行gradle build任务成功构建jar。

当我尝试运行测试代码时出现以下错误

**Error :**

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
    at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:314)
    at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:268)
    at java.util.jar.JarVerifier.processEntry(JarVerifier.java:273)
    at java.util.jar.JarVerifier.update(JarVerifier.java:228)
    at java.util.jar.JarFile.initializeVerifier(JarFile.java:383)
    at java.util.jar.JarFile.getInputStream(JarFile.java:450)
    at sun.misc.JarIndex.getJarIndex(JarIndex.java:137)
    at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:839)
    at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:831)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.misc.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:830)
    at sun.misc.URLClassPath$JarLoader.<init>(URLClassPath.java:803)
    at sun.misc.URLClassPath$3.run(URLClassPath.java:530)
    at sun.misc.URLClassPath$3.run(URLClassPath.java:520)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.misc.URLClassPath.getLoader(URLClassPath.java:519)
    at sun.misc.URLClassPath.getLoader(URLClassPath.java:492)
    at sun.misc.URLClassPath.getNextLoader(URLClassPath.java:457)
    at sun.misc.URLClassPath.getResource(URLClassPath.java:211)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:365)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)

**Development environment :**

Eclipse version : Version: Neon.1a Release (4.6.1)
Gradle Version: 3.2.1
Java version :/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home

**Try 1 : I tried the below solution but still getting the error :**

http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar

**Try 2 : below solution i tried by excluding from the above link  

jar {
    doFirst {
        from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it)
        exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'        
         } }
        manifest.attributes "Main-Class" : "Main",
        'Implementation-Version': version,
        "Class-Path": configurations.compile.collect { it.getName() }.join(' ')             
        zip64 true
    }   
}

**Below is my eclipse project explorer :**
[enter image description here][1]

**Below is my java build path in eclipse :**
[enter image description here][2]

  [1]: https://i.stack.imgur.com/fJWtC.png
  [2]: https://i.stack.imgur.com/0cRqR.png

为了解决这个问题,我已经创建了示例hello world gradle但是在我的eclipse ide和以下工作正常是gradle代码快照以供您参考

dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.21'

// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
 }

感谢您的帮助进一步调试以解决此问题

0 个答案:

没有答案