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
C:\Users\Mark>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" %*"

File type 'JARFile' not found or no open command associated with it.
 

Mark Stuart

Active Member
Licensed User
Longtime User
We're (I'm) screwing up: jdk 19 doesn't have c:\java\javafx\lib

This thread is about

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

Mine does. My java folder is a direct reflection of the installation directions from the B4X webpage.
 

Attachments

  • jAVAfx_lIB.png
    jAVAfx_lIB.png
    32.3 KB · Views: 6

LucaMs

Expert
Licensed User
Longtime User
I won't do the install as yet. I need confirmation from @Erel to see if this is really required.
After all, the B4X webpage did instruct us to download this: OpenJDK 19 + OpenJFX: download link.
Shouldn't that download contain the JavaFX that the Oracle page has on it?

Your message arrived while I was typing mine. You already have JavaFx, so that's fine.
Mine does
 

Mark Stuart

Active Member
Licensed User
Longtime User
I already did that.


C:\Users\Mark>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" %*"
File type 'JARFile' not found or no open command associated with it.
 

Mark Stuart

Active Member
Licensed User
Longtime User
Mark, please, help me... to help you 😄

If you run, inside A DOS window:

java -?
and press Enter,

do you see Java Help in the DOS window?
Yes. I ran the above command. Didn't you see that?
And I did run java -?
I saw all the command options. I don't know what to do with all that.
 
Top