B4J Tutorial Run B4J java and javafx UI Applications on Linux ARM32, ARM64 & Intel/AMD Computers and VPSs

To run a B4J console or GUI Application on any 32-bit or 64-bit ARM computer, follow these steps:

Have tested it on Raspberry Pi 4 and Orange Pi Zero 3, 2W running Ubuntu 21.04 and 22.04 respectively:

[edit - Also works with 32-bit Raspberry Pi OS on RPI 3 - see @dave4cbu post below]

[edit - 21-09-2024: This will not work (for obvious reasons) with Libraries such as "ControlsFX" that require Java 8]

[edit 10-01-2025: Tested and works with Ubuntu Linux running on x64 Intel processor based computers and VPSs. So it's not just limited to ARM - See Post#6 ]

STEP 1: Install openjfx11+

sudo apt-get update
sudo apt-get install openjfx

STEP 2: Find out where openJfx is installed

dpkg-query -L openjfx

NOTE: ..... should be installed in /usr/share/openjfx

STEP 3: Install OpenJDK11+ JRE (or whatever version the default JRE is) and check version

sudo apt install default-jre

sudo java -version

STEP 4: Run Program

sudo java -jar --module-path /usr/share/openjfx/lib --add-modules javafx.controls yourB4Jprogram.jar

NOTE: You can run B4J jar files compiled with Oracle Java 8 as well as OpenJDK11+

Note [10-01-2025]: If you get the error message "Authorization required, but no authorization protocol specified" run the above command without the "sudo"

Instead of typing the long command line, you can create a shell script with the above command line and pass your jar file as a parameter:

1. Create a file called "jrun" with the following two lines:

#!/bin/bash
sudo java -jar --module-path /usr/share/openjfx/lib --add-modules javafx.controls $1


2. Make the file executable:

chmod +x jrun

3. Run the program with a simplified command line:

./jrun yourB4Jprogram.jar


Enjoy! :)




----------------------------------------------------------------------------
 
Last edited:

dave4cbu

Member
Licensed User
Longtime User
To run a B4J console or GUI Application on any 64-bit ARM computer, follow these steps:

Have tested it on Raspberry Pi 4 and Orange Pi Zero 3, running Ubuntu 21.04 and 22.04 respectively:

STEP 1: Install openjfx11

sudo apt-get update
sudo apt-get install openjfx

STEP 2: Find out where openJfx is installed

dpkg-query -L openjfx

NOTE: ..... should be installed in /usr/share/openjfx

STEP 3: Install OpenJDK11 and check version

sudo apt install default-jre

sudo java -version

STEP 4: Run Program

sudo java -jar --module-path /usr/share/openjfx/lib --add-modules javafx.controls yourB4Jprogram.jar

NOTE: You can run B4J jar files compiled with Oracle Java 8 as well as OpenJDK11


Instead of typing the long command line, you can create a shell script with the above command line and pass your jar file as a parameter:

1. Create a file called "jrun" with the following two lines:

#!/bin/bash
sudo java -jar --module-path /usr/share/openjfx/lib --add-modules javafx.controls $1


2. Make the file executable:

chmod +x jrun

3. Run the program with a simplified command line:

./jrun yourB4Jprogram.jar


Enjoy! :)




----------------------------------------------------------------------------
This is brilliant thanks. Just got my B4J app running on a Raspberry pi3.
Works perfectly.
 

aminoacid

Active Member
Licensed User
Longtime User
This is brilliant thanks. Just got my B4J app running on a Raspberry pi3.
Works perfectly.

That's good to know. Just curious to know whether you installed it on Ubuntu or Raspberry Pi OS. Which Version and whether the OS was 32bit or 64bit?
 

dave4cbu

Member
Licensed User
Longtime User
That's good to know. Just curious to know whether you installed it on Ubuntu or Raspberry Pi OS. Which Version and whether the OS was 32bit or 64bit?
Raspberry pi OS 32bit version.
Just noticed that the touch screen isn't working with my app so I need to figure out what's going on there but works well with keyboard & mouse so cheers for that.
 

max123

Well-Known Member
Licensed User
Longtime User
Many thanks @aminoacid for detailed explanation.

I have some questions here...

1) Is this supposed to be working on Desktop PC (non-ARM) with linux too ?
2) How much is different this, than create the full installer with Create Standalone Package ?

Personally I never managed it, in past with Java8 I was able to just double-click jar files on linux
to run any B4J app, but this is not possible with Java11.

3) And because do not create 2 different bash scripts to fully automate it ?
- one to install Java and JavaFx
- one to launch applications by passing the jar as argument

In past I've done a similar thing to fully automate the installation of the OpenArena game on Raspberry,
please take a look here: https://github.com/maxmeli123/Raspberry-Mods/tree/master/OpenArena
This only require just some seconds to have the working game, the script is simple and fully automated on terminal, it even check if the GPU OpenGL
driver is enabled in the Raspberry config and even create the desktop launcher to launch it. I posted it, may the code can help.

This is an old code I used on Raspberry PI 3, it even works on Raspberry Zero W.
I do not know if it works now, may repositories still be changed and the script fails.

Thanks
Max
 
Last edited:

aminoacid

Active Member
Licensed User
Longtime User
Many thanks @aminoacid for detailed explanation.

I have some questions here...

1) Is this supposed to be working on Desktop PC (non-ARM) with linux too ?
2) How much is different this, than create the full installer with Create Standalone Package ?

Personally I never managed it, in past with Java8 I was able to just double-click jar files on linux
to run any B4J app, but this is not possible with Java11.

3) And because do not create 2 different bash scripts to fully automate it ?
- one to install Java and JavaFx
- one to launch applications by passing the jar as argument

In past I've done a similar thing to fully automate the installation of the OpenArena game on Raspberry,
please take a look here: https://github.com/maxmeli123/Raspberry-Mods/tree/master/OpenArena
This only require just some seconds to have the working game, the script is simple and fully automated on terminal, it even check if the GPU OpenGL
driver is enabled in the Raspberry config and even create the desktop launcher to launch it. I posted it, may the code can help.

This is an old code I used on Raspberry PI 3, it even works on Raspberry Zero W.
I do not know if it works now, may repositories still be changed and the script fails.

Thanks
Max

Hi! Yes, I have successfully installed OpenJDK 21 using the above procedure on an x64 Intel-processor based Laptop Computer running Ubuntu Linux. Also tried it successfully on a Intel-based VPS running Ubuntu 22.04 and XFCE Desktop. Once installed you can run JAR files compiled with Oracle Java8 or OpenJDK.

And yes, I don't see why you cannot create another script to automate the installation procedure shown above. It should work fine.

[edit] I missed your other question - The stand-alone package is a windows application (EXE) and will only run under windows. There is no equivalent for Linux as far as I know, so the only way to run the JAR file in Linux is by using a shell script as shown above.
 
Last edited:

max123

Well-Known Member
Licensed User
Longtime User
Hi @aminoacid, thanks, I tried it on VirtualBox with Lubuntu 18.04, but I only can run jar files compiled with Java8, not with OpenJDK11.
I just tried this my app, it says Audioclip is not recognized, so I tried to add javafx.media module to the run command, but it do not recognize it.
The same app compiled with Java8 works without add javafx.media module to the run command.

[edit] I missed your other question - The stand-alone package is a windows application (EXE) and will only run under windows. There is no equivalent for Linux as far as I know, so the only way to run the JAR file in Linux is by using a shell script as shown above.
I've read in the forum that is possible, but I'm not pratical with InnoSetup.

The main problem on both Win and Linux is that every app packaged contains the java JRE runtime, so apps are big, consume mutch more space, imagine to have 100-200 and more apps at 50 - 60MB each + resource files.

The best approach should be to just install Java in place, then reuse JRE to launch every app, but as I known this is a Java limitation, may for security reasons...

I currently have the same problem with my WebGL library I released some days ago, on B4J I use three.js distibution in place, then any app use this shared.
Now I ported the library to B4A, in Android this is not possible and I have to put it on every project inside Asset folder, then copy by code inside DirInternal
and unzip it, but every app contains it, so result a lot bigger.
 
Last edited:

aminoacid

Active Member
Licensed User
Longtime User
Hi @aminoacid, thanks, I tried it on VirtualBox with Lubuntu 18.04, but I only can run jar files compiled with Java8, not with OpenJDK11.

Do you know which version JRE was installed? [Step 3]
The default JRE installed for Lubuntu 18.04 may be older than v11

I've read in the forum that is possible, but I'm not practical with InnoSetup.

Again, I may be mistaken, but InnoSetup is an installer only for Windows. Regardless, you are correct - it would not be a good approach to have redundant packages with the JRE installed on the same system.
 

max123

Well-Known Member
Licensed User
Longtime User
Do you know which version JRE was installed? [Step 3]
The default JRE installed for Lubuntu 18.04 may be older than v11
In [Step 3] I installed it with:
sudo apt install openjdk-11-jdk
to be sure it is Java 11, it even contains the JRE.

Again, I may be mistaken, but InnoSetup is an installer only for Windows.
Ok, probably I confuse and do not use InnoSetup, but I've read on the forum that is possible to linux too, I'm not sure how, may using other tools but with a file that packager or InnoSetup export.

EDIT: This now worked. Many thanks for your tips.
sudo java -jar --module-path /usr/share/openjfx/lib --add-modules ALL-MODULE-PATH MidiKontrol.jar
But now I want to know because it not accept javafx.media, AudioClip should be inside here I think... but Im not sure....
Probably I use wrong syntax to add more modules ?
 

Attachments

  • Immagine 2025-01-12 today.png
    Immagine 2025-01-12 today.png
    432 KB · Views: 18
  • Immagine 2025-01-12 today2.png
    Immagine 2025-01-12 today2.png
    505.3 KB · Views: 13
Last edited:

peacemaker

Expert
Licensed User
Longtime User
1. Create a file called "jrun" with the following two lines:

#!/bin/bash
sudo java -jar --module-path /usr/share/openjfx/lib --add-modules javafx.controls $1
to have redundant packages

But this is the only single way (just single Java files set) for any qty of B4J apps on single Linux host... if just place the Java files manually once.
 

aminoacid

Active Member
Licensed User
Longtime User
In [Step 3] I installed it with:

to be sure it is Java 11, it even contains the JRE.


Ok, probably I confuse and do not use InnoSetup, but I've read on the forum that is possible to linux too, I'm not sure how, may using other tools but with a file that packager or InnoSetup export.

EDIT: This now worked. Many thanks for your tips.

So just to be clear and for the record, using the following command line with ALL-MODULE-PATH worked with the media library that you needed to include:

sudo java -jar --module-path /usr/share/openjfx/lib --add-modules ALL-MODULE-PATH MidiKontrol.jar
 

max123

Well-Known Member
Licensed User
Longtime User
So just to be clear and for the record, using the following command line with ALL-MODULE-PATH worked with the media library that you needed to include:

sudo java -jar --module-path /usr/share/openjfx/lib --add-modules ALL-MODULE-PATH MidiKontrol.jar
Yes, but how to add only required modules without use ALL-MODULE-PATH ?
 

BugZapper

New Member
Yes, but how to add only required modules without use ALL-MODULE-PATH ?
I believe it will only access the modules it needs to you don't have to individually select the modules. Besides doing that will not have any impact on the size or execution of your program since this is happening at run time and not compile time. See this:

.... When used with --add-modules, it adds all observable modules found on the module path to the module graph. This allows your application to access all the modules present as needed without explicitly listing them individually.....
 
Top