0

My goal is to create a Windows ".exe" file for my JavaFX Pac-Man game, see https://github.com/armin-reichert/pacman-javafx.

I followed the instructions from the Gluon website https://docs.gluonhq.com/#platforms_windows and installed all the required tools.

UPDATE: After having removed all hyphens from the Maven artifact name and all paths, I am able (after running mvn clean install) to

  1. Run the application using mvn gluonfx:run or mvn gluonfx:runagent
  2. Build the native Window application with mvn gluonfx:build and mvn gluonfx:package. Not sure if mvn gluonfx:install is needed?

But when I try to run the native application using mvn gluonfx:nativerun, exceptions occur because resources cannot be loaded (fixed).

My application is modular, module name is "de.amr.games.pacman.ui.fx".

The resource files are all in subfolders under "src/main/resources/de/amr/games/pacman/ui/fx".

The application runs from my IDE (Eclipse) or with the gluonfx targets mentioned above, but the native application cannot access the resources (sounds etc.).

UPDATE #2:

To have .mp3 and .wav files loaded successfully, I had to add the following lines to the "resources" block in file src\main\resources\META-INF\native-image\resource-config.json:

  "includes":[
->  {"pattern": ".*\\.mp3$"},
->  {"pattern": ".*\\.wav$"},

But when running the native application, now the following exception occurs:

[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB] 06:46:02.273 INFO  de.amr.games.pacman.ui.fx.app.PacManGameAppFX - Starting application... [JavaFX Application Thread]
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB] 06:46:02.273 TRACE de.amr.games.pacman.ui.fx.sound.AbstractGameSounds - Try loading clip from 'resource:/de/amr/games/pacman/ui/fx/sound/pacman/pacman_death.wav' [JavaFX Application Thread]
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB] Exception in Application start method
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB] Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at java.lang.Thread.run(Thread.java:833)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.oracle.svm.core.windows.WindowsPlatformThreads.osThreadStartRoutine(WindowsPlatformThreads.java:143)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB] Caused by: java.lang.UnsatisfiedLinkError: no glib-lite in java.library.path
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.oracle.svm.core.jdk.NativeLibrarySupport.loadLibraryRelative(NativeLibrarySupport.java:132)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:47)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at java.lang.Runtime.loadLibrary0(Runtime.java:818)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at java.lang.System.loadLibrary(System.java:1989)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:166)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:54)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.media.jfxmediaimpl.NativeMediaManager.lambda$new$0(NativeMediaManager.java:111)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at java.security.AccessController.executePrivileged(AccessController.java:145)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at java.security.AccessController.doPrivileged(AccessController.java:569)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.media.jfxmediaimpl.NativeMediaManager.<init>(NativeMediaManager.java:108)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.media.jfxmediaimpl.NativeMediaManager$NativeMediaManagerInitializer.<clinit>(NativeMediaManager.java:78)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.media.jfxmediaimpl.NativeMediaManager.getDefaultInstance(NativeMediaManager.java:90)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.media.jfxmedia.MediaManager.canPlayProtocol(MediaManager.java:78)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.media.jfxmedia.locator.Locator.<init>(Locator.java:240)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.media.jfxmediaimpl.NativeMediaAudioClip.<init>(NativeMediaAudioClip.java:53)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.media.jfxmediaimpl.NativeMediaAudioClip.load(NativeMediaAudioClip.java:63)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.media.jfxmediaimpl.AudioClipProvider.load(AudioClipProvider.java:66)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.media.jfxmedia.AudioClip.load(AudioClip.java:135)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at javafx.scene.media.AudioClip.<init>(AudioClip.java:83)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at de.amr.games.pacman.ui.fx.sound.AbstractGameSounds.load(AbstractGameSounds.java:82)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at de.amr.games.pacman.ui.fx.sound.pacman.PacManGameSounds.<init>(PacManGameSounds.java:42)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at de.amr.games.pacman.ui.fx.shell.GameUI.<clinit>(GameUI.java:69)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at de.amr.games.pacman.ui.fx.app.PacManGameAppFX.start(PacManGameAppFX.java:100)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at java.security.AccessController.executePrivileged(AccessController.java:169)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at java.security.AccessController.doPrivileged(AccessController.java:399)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.oracle.svm.jni.JNIJavaCallWrappers.jniInvoke_VA_LIST_Runnable_run_16403f8d32adb631126daa893e5e80085c5d6325(JNIJavaCallWrappers.java:0)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.glass.ui.win.WinApplication._runLoop(WinApplication.java)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
[Sa. Juli 02 06:46:02 MESZ 2022][INFO] [SUB]    ... 3 more

The problem seems to be the "resource:" URL protocol (getClass().getResource(...) is used in the code). When running mvn gluonfx:runagent, the URLs have a "file:" protocol and sounds are loaded.

Without sound, the application runs fine, so this is the last remaining issue.

UPDATE #3:

If I comment-out the creation of JavaFX AudioClip objects in my code, the native application works fine!

UPDATE #4:

I think this issue is related to: https://github.com/gluonhq/substrate/issues/336

UPDATE #5:

Just found out about the Gluon Attach library and tried it out. Is my impression correct that there does not exist an audio service for platform "Desktop"? So I cannot load audio files from a native Windows app using Gluon Attach?

Thanks for any hints how to solve this issue.

Armin Reichert

  • Did you try `mvn gluonfx:runagent` before doing the native build? – José Pereda Jun 30 '22 at 11:42
  • Thanks, José! `mvn gluonfx:runagent` indeed starts the application. But how to proceed from here? There is a pacman-ui-fx-exe file created but nothing happens when I double-click it. – Armin Reichert Jun 30 '22 at 12:34
  • After `gluonfx:runagent` you need to build the native application again. See https://docs.gluonhq.com/#_goals – José Pereda Jun 30 '22 at 12:41
  • After restructuring my `src/main/resources` folder and adapting the classes that load resources I can successfully run the targets `gluonfx:run`, `gluonfx:runagent` and `gluonfx:build`. However, the target `gluonfx:package`fails with an error message: [Do. Juni 30 16:35:32 MESZ 2022][SEVERE] Process Wix Compiler failed with result: 14 In the Wix log file it says that my project folder name (which contains hyphens) leads to an illegal identifier for Windows. Does that mean I need to rename my project folder to not contain hypens? – Armin Reichert Jun 30 '22 at 14:45
  • Did you try `mvn gluonfx:nativerun` before packaging? Just make sure native image works fine. For packaging, you might simply change the `` in your pom. – José Pereda Jun 30 '22 at 15:13
  • Updated text after having learned that problem seems to be related to resource loading and not to log4j. – Armin Reichert Jul 01 '22 at 09:00
  • See https://docs.gluonhq.com/#_resourceslist ? – José Pereda Jul 01 '22 at 09:06

0 Answers0