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:

epiCode

Active Member
Licensed User
Article updated to handle issues running Jar file for openJDK 11 and above for Jar files using javafx.web !
 

Mark Stuart

Active Member
Licensed User
Longtime User
When running the first command - with changes made to my installation path - the command fails with:
File type 'JARFile' not found or no open command associated with it.

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" %*"


And the second command fails with:
Access is denied.
Error occurred while processing: .jar.

assoc .jar=JARFile

And looking for JARFILE in the registry, does not exist.
As you can see, I downloaded the latest jdk from the B4X web instructions.

So what gives?

Mark Stuart
 
Last edited:

epiCode

Active Member
Licensed User
When running the first command - with changes made to my installation path - the command fails with:
File type 'JARFile' not found or no open command associated with it.

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" %*"
just run following in "elevated cmd" window and check if your output is similar:

B4X:
c:\>ftype | find "jar"
JARFile="c:\java\bin\javaw.exe" -jar --module-path c:\java\javafx\lib --add-modules javafx.controls "%1" %*"
 

Mark Stuart

Active Member
Licensed User
Longtime 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!!
 

LucaMs

Expert
Licensed User
Longtime 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!!
ftype and JARfile are NOT executable, they are part of JRE.

Your system (Windows) cannot find java.exe.
Try reinstalling Java or you will have to manually change some system variables.

When installing Java, the installer often automatically sets some essential environment variables, such as PATH, which includes the path to the Java bin folder to allow running the java and javac commands from the terminal. However, not all variables (e.g., JAVA_HOME) are always created automatically.

In Windows 10, to manually create or modify Java environment variables you can do the following:
  1. Open the Start menu and search for "Environment Variables" or go to:
    Control Panel > System > Advanced system settings > Environment Variables.
  2. In the "Environment Variables" window you can create or modify:
    • User variables (current user only)
    • System variables (for all users)
  3. For Java, it is normally recommended to create/modify the JAVA_HOME variable, assigning it the path to the JDK installation folder (e.g. C:\Program Files\Java\jdk-version).
  4. Change the PATH variable to include the path %JAVA_HOME%\bin (or directly the Java bin folder).
 

Mark Stuart

Active Member
Licensed User
Longtime User
Does this look correct?
Been a long time since I edited this stuff - Windows 7.
 

Attachments

  • EnvironmentVariables.png
    EnvironmentVariables.png
    30.1 KB · Views: 17

Mark Stuart

Active Member
Licensed User
Longtime User
So if this is correct, what now?
I just double-click the .jar file?

EDIT: well that didn't work

Because, I'm not going to clutter my hard drive with B4JPackager installed apps.
The B4X development team should of had an alternative answer for this, to not just using the B4JPackager.
They're the smart ones around here. :)
 

LucaMs

Expert
Licensed User
Longtime User

Mark Stuart

Active Member
Licensed User
Longtime User
I moved the User to System for the JAVA_HOME and Path entries.
Is that correct?
And I guess I restart the computer for that to take effect.
Then what is need after all theses changes?

Mark
 

Attachments

  • EnvironmentVariables_System.png
    EnvironmentVariables_System.png
    34.3 KB · Views: 11
  • EnvironmentVariables_SystemPath.png
    EnvironmentVariables_SystemPath.png
    19.1 KB · Views: 13
Last edited:
Top