jlink packages current platform's binaries

泪湿孤枕 提交于 2021-02-19 03:58:07

问题


I am trying to build cross-platform archives of an application built using Java 11 and packaged with jlink.

For the cross-platform packaging I am basing my build on this answer. I have managed to make my Gradle build download the target platform's JDK and invoke jlink with the appropriate jmods folder, however the target image always includes the binaries and JRE structure of the host platform (in my case Windows, meaning the generated bin folder always includes DLLs and Windows executables). If I supply the --strip-native-commands flag then no executables are included at all, although the DLLs still are.

Is there any way to make jlink package the correct JRE files?

Host JDK: Windows Oracle JDK 11.0.10 x64

Target JDK: OpenJDK 11.0.2 x64

Sample Linux invocation:

C:\Program Files\Java\jdk-11.0.10/bin/jlink.exe
  --module-path C:\projectdir\build\install\project-linux\lib;C:\projectdir\build\JREs\linux\jmods
  --add-modules com.acme.app
  --compress 2
  --launcher app=com.acme.app/com.acme.app.Main
  --no-header-files
  --no-man-pages
  --strip-debug
  --dedup-legal-notices=error-if-not-same-content
  --output C:\projectdir\build\packageFiles\linux

GraalVM

Using GraalVM CE Java 11 21.0.0 yields:

java.io.IOException: Invalid JMOD file: C:\jdks\graalvm-ce-java11-21.0.0\jmods\java.base.jmod

Which makes it seem like GraalVM's jlink always attempts to use the host's JMOD files.

OpenJDK

Using OpenJDK 11.0.2 x64 yields the same result of including the host's binary files in the created runtime image. The same behaviour is true for Zulu OpenJDK 11.0.10+9 x64.


回答1:


Found the issue: the problem was with my reference to the jmods directory of both the Linux and the MacOS JDK distributions.

For the Linux one I mistakenly setup the build to download version 11.0.1 instead of 11.0.2, which ended up leading to the logic to flatten the hierarchy not flattening it. This means that the build/JREs/linux/jmods reference wasn't targeting any existing folder, meaning that jlink doesn't find the JDK modules there hence the host files being included.

The MacOS JDK has a completely different file structure so the flattening logic was just wrong. Ultimately this lead to the same missing jmods folder symptom.

With both issues fixed the jlink tool now correctly packages the target JDK's files when building cross-platform runtime images.



来源:https://stackoverflow.com/questions/66083431/jlink-packages-current-platforms-binaries

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