We have some problem in getting a JavaFx and JMonkey project running in Maven. The project is running without any issues in Gradle. But when we try to get it running in Maven we get a ".jar file not found in classpath" error at runtime.
For setting up the project I have followed the instructions found in: https://openjfx.io/openjfx-docs/
However the project not only uses openjfx libraries but also jmonkey libraries(for this not much documentation is available for Maven setup).
I have tried both the below approaches:
- JavaFX and Eclipse --> Non-modular with Maven
- JavaFX and Eclipse --> Modular with Maven
Case 1: When I try the Method 1, non-modular with Maven(project does not have module-info.java file), all the Maven dependencies are coming under the ModulePath, instead of ClassPath, automatically. I was not able to figure out why this happens but it probably has something to do with the fact that JavaFX is added as external modules to the project since they are no longer part of the JDK. And when there are libraries in the modulepath, they cannot have shared packages. But this is not the case for most of the libraries in the MavenDependencies.
So in case of Method 1, I get an error similar to the following:
java.lang.module.ResolutionException: Both Modules A and B export some package to module C
Case 2: In Method 2, modular with Maven, the project contains module-info.java and we specify the necessary modules being used by the project. So this includes all the javafx modules and from jmonkey we include the jme3.core module and the jme-jfx bridge module.
In this case, the project builds successfully but at runtime we get the following error:
SEVERE: Failed to find a JmeSystem delegate! Ensure either desktop or android jME3 jar is in the classpath. Exception in thread "Thread-3" java.lang.NullPointerException at [email protected]/com.jme3.system.JmeSystem.newContext(JmeSystem.java:159) at [email protected]/com.jme3.app.LegacyApplication.start(LegacyApplication.java:461) at [email protected]/com.jme3.app.LegacyApplication.start(LegacyApplication.java:424) at [email protected]/com.jme3.app.SimpleApplication.start(SimpleApplication.java:125) at java.base/java.lang.Thread.run(Thread.java:835)
But the jme3-desktop.jar is available in the classpath and is getting ignored because a related jar jme3-core.jar is present in the MODULEPATH. I read in another stackoverflow post that in such scenarios javac ignores classpath and only considers modulepath. In order to fix this issue I tried to include jme3.desktop also in the module-info.java, but this is not allowed because both jme3.core and jme3.desktop have shared packages.
If anyone can provide some guidance on how to setup the Project correctly with Maven, it would be of great help.