-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[native-image] java.home property not set #1812
Comments
I have a similar issue. I use D:\code\python\fun_player>D:\code\python\fun_player\target\midi_player.exe D:\Downloads\Never-Gonna-Give-You-Up-1.mid
Exception in thread "main" java.lang.Error: Can't find java.home ??
at com.sun.media.sound.JSSecurityManager.lambda$loadProperties$1(JSSecurityManager.java:90)
at java.security.AccessController.doPrivileged(AccessController.java:87)
at com.sun.media.sound.JSSecurityManager.loadProperties(JSSecurityManager.java:87)
at com.sun.media.sound.JDK13Services.getProperties(JDK13Services.java:192)
at com.sun.media.sound.JDK13Services.getDefaultProvider(JDK13Services.java:177)
at com.sun.media.sound.JDK13Services.getDefaultProviderClassName(JDK13Services.java:118)
at javax.sound.midi.MidiSystem.getDefaultDevice(MidiSystem.java:1096)
at javax.sound.midi.MidiSystem.getDefaultDeviceWrapper(MidiSystem.java:1078)
at javax.sound.midi.MidiSystem.getSequencer(MidiSystem.java:379)
at javax.sound.midi.MidiSystem.getSequencer(MidiSystem.java:339)
at com.liudonghua.examples.App.main(App.java:27)
D:\code\python\fun_player>java -jar target\midi_player-0.1.0.jar D:\Downloads\Never-Gonna-Give-You-Up-1.mid
D:\code\python\fun_player> |
This error comes from https://github.com/openjdk/jdk/blob/890adb6410dab4606a4f26a942aed02fb2f55387/src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java#L90. It seems And from the doc https://www.graalvm.org/22.1/reference-manual/native-image/Properties/, I should add |
While trying to generate a native image from a simple sample using the java.awt.Font class, I've noticed that the java.home variable is not set.
Since native-image aims at creating self contained executables which run independently of any available JRE, this is expected behavior.
However, some Java classes require it to load resources from the respective location.
In my case, the use fonts triggers a font configuration file to be loaded, which terminates with the following exception:
Setting the variable at runtime works, but means that the image either requires an installed JRE or needs to be bundled with the respective resources from the JRE manually.
Even if this is pretty easy to work around, I think it might be worth providing a standardised or automated way to bundle JRE resources, especially since JRE provided classes should work with as litte manual tinkering as possible.
This could be done by adding an additional configuration file, like the ones that allow reflection or JNI access. Using this file, a directory containing all required JRE resources could be created alongside the native image and JAVA_HOME could be pointed there.
As I am not entirely sure how many cases would profit from this and how often resources are loaded from JAVA_HOME, an approach like this might be overly complex. As an alternative, providing premade archives that contain all of the respective resources might yield similar results without any major tradeoffs.
The text was updated successfully, but these errors were encountered: