The purpose of this article is to explain the Java Invalid Signature File error you may encounter when running a java jar file. When building a jar file that contains other jar files with standard build tools you should not encounter this error. However, you may encounter the error when using the maven shade plugin.
The specific error condition is the following:
java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
This means that you have packaged a signed jar file inside of another jar file. The solution is to exclude the signature files. In your maven shade plugin configuration, add the following.
<configuration> <filters> <filter> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> <!-- Additional configuration. --> </configuration>
Now you should be able to rebuild your jar file and it will run successfully, without the error.
This article has demonstrated how to recover from a Java invalid signature error when executing a jar file. Leave us a comment with any questions. Be sure to read some of our other posts!