B4J Question Trying to Use the Latest Java 23 and JavaFX 23

xulihang

Active Member
Licensed User
Longtime User
I am trying to use the early builds of JDK 23 and JavaFX 23, since the latest code base of JavaFX has fixed a bug that really matters to my app.

1. Download the builds from here: https://jdk.java.net/23/, https://jdk.java.net/javafx23/
2. Run the jar with the following command:

B4X:
G:\jdk-23\bin\java --module-path "G:\javafx-sdk-23\lib" --add-modules javafx.base,javafx.controls,javafx.graphics,javafx.web,javafx.swing --add-opens javafx.controls/com.sun.javafx.scene.control.skin=ALL-UNNAMED --add-exports javafx.base/com.sun.javafx.collections=ALL-UNNAMED -jar .\ImageTrans.jar


I added some parameters after encountering the following problems:

B4X:
java.lang.reflect.InaccessibleObjectException: Unable to make public static double com.sun.javafx.scene.control.skin.Utils.computeTextHeight(javafx.scene.text.Font,java.lang.String,double,javafx.scene.text.TextBoundsType) accessible: module javafx.controls does not "exports com.sun.javafx.scene.control.skin" to unnamed module @1aba25ec

B4X:
error: java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject cannot access class com.sun.javafx.collections.VetoableListDecorator (in module javafx.base) because module javafx.base does not export com.sun.javafx.collections to unnamed module @3276b83b
StackTrace: java.lang.IllegalAccessException: class anywheresoftware.b4j.object.JavaObject cannot access class com.sun.javafx.collections.VetoableListDecorator (in module javafx.base) because module javafx.base does not export com.sun.javafx.collections to unnamed module @3276b83b
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:398)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:709)
    at java.base/java.lang.reflect.Method.invoke(Method.java:571)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)


I wonder why I need to add the parameters and what else I need to do to make the B4J app compatible with the latest versions of Java and JavaFX.
 

Daestrum

Expert
Licensed User
Longtime User
I have noticed, the higher the versions get, the more they enforce the 'com.sun. ...' are not public apis and make the developer add extra code to continue using them.
Usually, they have an alternate that is a public api eg, com.sun.javafx.collections... >> javafx.collections although not all classes/methods will be available.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
As an aside, looking at your run command in post #1, it looks like you haven't set up java23 as B4J expects with javafx inside the jdk directory.
 
Upvote 0

xulihang

Active Member
Licensed User
Longtime User
Well, I cannot use JDK 23 for compiling. It sees it as Java 8.

B4X:
B4J Version: 8.80
Parsing code.    (0.67s)
    Java Version: 8
Building folders structure.    (0.04s)
Compiling code.    (0.60s)
Compiling layouts code.    (0.02s)
Organizing libraries.    (0.00s)
Compiling generated Java code.    Error
error: Source option 7 is no longer supported. Use 8 or later.

javac 23-ea
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
When I use the later jdk's I have to add the #JavaCompilerPath to the app
B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
    #JavaCompilerPath: 23, c:/jdk-23/bin/javac.exe
#End Region
1715934281362.png

Or else I get javafx missing etc
 
Upvote 2
Top