Signing java 11 jar with jarsigner duplicate entry module-info.class

北慕城南 提交于 2019-12-05 09:58:13

Based on what you have posted of your build.gradle, when you run:

./gradlew jar

you are creating a fat/shadow jar, that bundles all of your dependencies, including the modular ones in one single big jar. This process extracts all the files from each jar (classes and resources) into the libs folder, and finally zips it into the shadow jar of your project.

The modular dependencies (at least JavaFX jars) include a module-info.class file in their jar file. So these will be added to the libs folder.

As a result of the jar task, and depending on your platform, you could end up with only one of these files (the first or the last one added, if files with same name are pasted into one single file), or with all of them (if all files even with the same name are kept, as this seems to be your case).

Either way, since you are creating a fat jar, you will run it as:

java -jar my-fat-jar.jar

and for this you don't need modules at all.

Solution

So one simple solution is to exclude the module-info files from your fat jar:

jar {
    manifest {
        attributes 'Main-Class': 'your.main.class'
    }
    from {
        exclude '**/module-info.class'
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

Cross-platform jar

Note that the jar you are releasing is not cross-platform, as it only contains the native libraries for Linux.

One option to create a cross-platform jar can be found here, section Non-modular application -> Gradle -> Cross-platform jar.

jlink

Alternatively you might consider using jlink for distribution, since your app is already modular.

In this case you will generate a custom image for a given platform. You can consider creating a one for each platform.

See this doc, section Modular with Gradle, and use the jlink task, or try the badass-jlink-plugin instead.

jpackage

There is a preview of the jpackage tool for Java 12. With it, you could create an installer for each platform.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!