Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in executing the generated jar file

I have a Java project with embedded jetty server and jersey library for REST Services. I am using Intellij for running the project and its working. The problem is when I try to execute the generated jar file.

So I have written a task for generating jar file in the build.gradle file. Below is the task in the build.gradle

task fatJar(type: Jar) {
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': 1.0
        attributes 'Main-Class': 'EmbeddedJetty.EmbeddedJettyMain'
    }
}

The jar file is generated when I run the below command

gradle clean build fatJar

I am facing the below errors when I try to the generated jar file using the command

java -jar projectname.rar

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:284)
    at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:238)
    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.URLClassPath$JarLoader$2.getInputStream(URLClassPath.java:940)
    at sun.misc.Resource.cachedInputStream(Resource.java:77)
    at sun.misc.Resource.getByteBuffer(Resource.java:160)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:454)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    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)

Can someone provide your feedback on what might be the issue?

like image 846
Maverick Avatar asked Mar 11 '23 23:03

Maverick


1 Answers

This is likely the result of bundling third party library jars that have been signed to prevent tampering. Your bundling is likely including signature files from these jars in your 'fat' jars manifest. You can explicitly exclude signature files using a directive like:

exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'

related question: "Invalid signature file" when attempting to run a .jar

like image 142
dkichler Avatar answered Mar 30 '23 09:03

dkichler