Invalid signature file digest

Full error text:

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

This error can be encountered if there are signed libraries among the dependencies of your project. To solve the problem, you need to exclude files with the extensions .SF, .DSA, .RSA from the build.

Of course, we will assume that you are building uber jar (fat jar).

For Maven:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>${maven-shade-plugin.version}</version>
    <executions>
        <execution>
            ...
            <configuration>
                <filters>
                    <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>

For Gradle:

exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA")

Complete code of the build task:

tasks.register<Jar>("uberJar") {
    archiveClassifier.set("uber")
    from(sourceSets.main.get().output)
    dependsOn(configurations.runtimeClasspath)
    from({
        configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
    })
    exclude("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA")
}

That’s all.

Telegram channel

If you still have any questions, feel free to ask me in the comments under this article or write me at promark33@gmail.com.

If I saved your day, you can support me 🤝

Leave a Reply

Your email address will not be published. Required fields are marked *