B4J Tutorial Running Jar with double click (in Java OpenJDK 11+ )

As shared in multiple places in this forum Java 11 OpenJDK does not allow to run jar files directly. (here)

Here is an easy workaround...

1. Run cmd with administrator privilege.
2. Type the following two commands:
B4X:
ftype JARFile="c:\java\bin\javaw.exe" -jar --module-path c:\java\javafx\lib --add-modules javafx.controls "%1" %*"

assoc .jar=JARFile

Replace the path "c:\java\bin\javaw.exe" and "c:\java\javafx\lib" based on your installed java folder.

UPDATE 16/03/2023:

If you have OpenJDK version greater than 11 and you are still unable to run a GUI based jar then try edit in Registry
1. Navigate to Computer\HKEY_CLASSES_ROOT\JARFile\Shell\Open\Command
2. In Default put this value (replace path with your java and javafx lib path) :

B4X:
"c:\java\bin\javaw.exe" -jar --add-opens javafx.controls/com.sun.javafx.scene.control.skin=ALL-UNNAMED --module-path c:\java\javafx\lib --add-modules javafx.controls,javafx.web "%1" %*

Cheers!
 
Last edited:

Mark Stuart

Active Member
Licensed User
Longtime User
Where is this JARFILE reference supposed to be?
As the first command failed. See above my reference to that.
Post #33
 

LucaMs

Expert
Licensed User
Longtime User
AGAIN :mad:

1758166272385.png
 

Daestrum

Expert
Licensed User
Longtime User
@Mark Stuart what windows version are you running?

ftype and assoc are c m d . e x e only, win 11 defaults to powershell.

c m d . e x e
ftype

Powershell
cmd /c ftype
 
Last edited:

epiCode

Active Member
Licensed User
C:\Users\Mark>c:\>ftype | find "jar"
'c:\' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Mark>JARFile="c:\java\bin\javaw.exe" -jar --module-path c:\java\javafx\lib --add-modules javafx.controls "%1" %*"
'JARFile' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Mark>

Not sure what to expect.
All I want to do is to be able to run a B4J app .jar file on a double-click.
Friggin' Oracle!!
"c:\>" is not to be typed. It is representation of cmd prompt
JARFile=...... is also not to be typed. it will be the output of ftype cmd. You need to match it with what is showing here. if it is not similar. then the cmd did not work for you. You can DM me I can help you troubleshoot it for you while you are online.
 

Mark Stuart

Active Member
Licensed User
Longtime User
@Mark Stuart what windows version are you running?

ftype and assoc are c m d . e x e only, win 11 defaults to powershell.

c m d . e x e
ftype

Powershell
cmd /c ftype
It's a new ASUS desktop with Windows 11 Home. My last computer died. So that's why I'm going thru all this reinstalling.
Thank you for clarifying the command without the 'c:\'.
I will give it another try. I'm not used to doing such commands so it's a bit much for me.
Nevertheless, I appreciate your online help.
 

Mark Stuart

Active Member
Licensed User
Longtime User
SUCCESS!
Thank you epiCode!

C:\Windows\System32>ftype JARFile="c:\java\jdk-19.0.2\bin\javaw.exe" -jar --module-path c:\java\jdk-19.0.2\javafx\lib --add-modules javafx.controls "%1" %*"
JARFile="c:\java\jdk-19.0.2\bin\javaw.exe" -jar --module-path c:\java\jdk-19.0.2\javafx\lib --add-modules javafx.controls "%1" %*"

C:\Windows\System32>assoc .jar=JARFile
.jar=JARFile

C:\Windows\System32>


It looks like both commands took this time. Phew!
Now I should be able to just launch a B4J .jar app, yes?
Here goes...

The .jar file shows an icon to the left of the .jar file - good.
But the association is: OpenJDK Platform binary.
Shouldn't it reference JRE instead?
Is that correct? 'Cause the cursor showed something happening, but the app did not launch/open.
 

Mark Stuart

Active Member
Licensed User
Longtime User
Issue solved. Thanx epiCode!

EDIT: no it's not resolved with this one particular .jar app, originally built with an older B4J version.
It runs in Debug mode and Release mode from the IDE, but again, not double-clicking the .jar file when the app is built using the Release (obfuscated) method.
This is very strange as I Release built the Hello World UI app and no problem launching/opening it.
B4J version is 10.30.

Using the C M D to launch the .jar file results with a java error:

C:\Windows\System32>java -jar "C:\Data Drive Transfer\Projects\B4J\SnippetsManagerForB4X\Objects\SnippetsForB4X.jar"
Error: JavaFX runtime components are missing, and are required to run this application


I ran the HelloWorld .jar file with the same command, same error.
If the JavaFX folder was installed/copied correctly, why does one .jar file work and the other doesn't?
Mystified!!
 
Last edited:
Top