B4J Question Running Jar File with OpenJDK Error

walterf25

Expert
Licensed User
Longtime User
Hi Everyone, I have been trying to find a way to make a project distributable for a couple of months, I am able to create an .exe file using the B4JPackager tool and Inno Setup, but for some reason I get some errors that I do not get when I run the project from within B4J, here's the thread for more context.

@Erel suggested I distribute the jar file along with OpenJDK and a batch file to launch the jar file, I have created the following batch file
batch file:
@ECHO OFF
TITLE RUN A JAR FILE
CD C:\Java\jdk-14.0.1\bin
javaw --module-path C:\Java\jdk-14.0.1\javafx\lib --add-modules ALL-MODULE-PATH -jar "C:\Users\wflores\Documents\B4J_Projects\WindowsCompanion\B4J\Objects\WindowsCompanion.jar"
::PAUSE

That batch file actually launches the Jar file, but I get this error right away and then the jar file closes.
b4xmainpage$ResumableSub_B4XPage_Created.resume (java line: -1)
java.lang.RuntimeException: java.lang.IllegalAccessError: class anywheresoftware.b4a.objects.B4XCanvas$B4XPath (in module b4j) cannot access class com.sun.javafx.geom.Path2D (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.geom to module b4j
at b4j/anywheresoftware.b4a.BA.raiseEvent2(Unknown Source)
at b4j/anywheresoftware.b4j.objects.CustomViewWrapper.AfterDesignerScript(Unknown Source)
at b4j/anywheresoftware.b4j.objects.LayoutBuilder.loadLayout(Unknown Source)
at b4j/anywheresoftware.b4j.objects.PaneWrapper.LoadLayout(Unknown Source)
at b4j/anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(Unknown Source)
at b4j/com.snap.companion.b4xmainpage$ResumableSub_B4XPage_Created.resume(Unknown Source)
at b4j/anywheresoftware.b4a.BA.checkAndRunWaitForEvent(Unknown Source)
at b4j/anywheresoftware.b4a.BA.raiseEvent2(Unknown Source)
at b4j/anywheresoftware.b4a.BA.raiseEvent(Unknown Source)
at b4j/anywheresoftware.b4a.keywords.Common$3.run(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(Unknown Source)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalAccessError: class anywheresoftware.b4a.objects.B4XCanvas$B4XPath (in module b4j) cannot access class com.sun.javafx.geom.Path2D (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.geom to module b4j
at b4j/anywheresoftware.b4a.objects.B4XCanvas$B4XPath.InitializeRoundedRect(Unknown Source)
at b4j/com.snap.companion.jpanel._buildgradients(Unknown Source)
at b4j/com.snap.companion.jpanel._designercreateview(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
... 17 more

I have added these two lines to the project in hopes of fixing this issue, but doesn't work.

Added Lines:
    #VirtualMachineArgs: --add-opens javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED
    #VirtualMachineArgs: --add-exports javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED

Does anyone know what else I can try, It is frustrating that it is so difficult to find a solution that can finally allow me to distribute this file, it is very trivial as I am on a deadline here at work, maybe I should have done this using a different platform, but lesson learned, as I have no more time I need to find a solution.

Thanks everyone
Walter
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
maybe you need to add the lines to #PackagerProperty too
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
maybe you need to add the lines to #PackagerProperty too
So, I tried adding this line also
B4X:
#PackagerProperty: AdditionalModuleInfoString = exports com.sun.javafx.geom;

But I still get the same error, any suggestions?

Walter
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I was thinking more the
B4X:
.

#PackagerProperty: VMArgs = --add-opens ...
you best check as I don't remember the format for it
 
Last edited:
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Just noticed in your original post, you are using javac - that's for compiling, you want java to run the jar (or javaw for no cmd window)
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Just noticed in your original post, you are using javac - that's for compiling, you want java to run the jar (or javaw for no cmd window)
Yes, I realized that too and also tried java and javaw, but doesn't make a difference as far as the error goes.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
So I was able to launch the jar file with the following command
Batch File:
C:\Java\jdk-11.0.1\jdk-11.0.1\bin\java --module-path C:\Java\jdk-11.0.1\jdk-11.0.1\javafx\lib --add-modules ALL-MODULE-PATH --add-exports javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED --add-opens javafx.graphics/javafx.scene.canvas=ALL-UNNAMED -jar .\jar.jar

Walter
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Did you try putting the add-opens on the

#PackagerProperty: VMArgs = --add-opens javafx.graphics/javafx.scene.canvas
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Did you try putting the add-opens on the

#PackagerProperty: VMArgs = --add-opens javafx.graphics/javafx.scene.canvas
Yes but this is only required if I want to create an executable, I have tried this already but while the jar file works fine, when I create an executable I get some other error which is why I am trying to distribute just the .jar file.
 
Upvote 0
Top