B4J Question Advice on running a jar file on Ubuntu

rspitzer

Active Member
A little background first, the B4X code runs on dedicated linux terminals that I sell. So when the terminal is powered up, after the desktop loads, the B4X application is started.
Currently I am running Ubuntu Mate (the boards are just commercial single board computers, not raspberry pi's). In Mate there is a resource to create a startup application. Basically I think its creating a cron job with the @reboot syntax, my theory at least. The startup application is just a terminal command. I modified the bashrc file to include a separate bash script to run the B4X application. So when the terminal opens it runs my application. From a users stand point, what the users sees is the Mate desktop appear, then a terminal window open, then the B4X application launching. My question is this the cleanest way of doing this. Ideally, the B4X application would launch as soon as the desktop launches, without the delay of the terminal windows opening. I cannot figure out a way of a direct launch from the desktop to the B4X application, I have tried numerous methods. My theory is that this is an issue with running Java and JavaFX from a desktop shortcut, and the only way to launch is from a terminal window. When I was using the Windows CE platform, I could modify the windows registry, so when windows CE started, the desktop would never appear and my application would just launch, a bit cleaner I thought. I am open to suggestions or advice on this, or maybe this is just the only way to do this. There are probably way smarter linux users out there than me.
 

rspitzer

Active Member
Just wanted to let this post know, I finally figured out how to run the jar file as a script, and auto boot it from the desktop when the system turns on, without having to open terminal. If someone's interested in this, I will leave an answer.
 
Upvote 0

John Naylor

Active Member
Licensed User
Longtime User
Just wanted to let this post know, I finally figured out how to run the jar file as a script, and auto boot it from the desktop when the system turns on, without having to open terminal. If someone's interested in this, I will leave an answer.
It's always useful for future readers if you post your solution too.
 
Upvote 0

rspitzer

Active Member
Making either a desktop short cut or startup application work immediately for a B4X application. Please note, this is a way I found, Linux and the various distros are rather flexible and I am no Linux Pro.

The main issue I had turned out to be making sure that the PATH_TO_FX was properly set as a permanent environment variable. I was running the B4X application from terminal, and I added the PATH_TO_FX statement to the end of the .bashrc file in the local home directory. So when I launched terminal, the PATH_TO_FX would be set, since opening terminal would first run the .bashrc file. Unfortunately this is not the case if you want to run a B4X application from the desktop, without first running terminal.
To change this and make the PATH_TO_FX permanent at login, you need to edit the text file:

/etc/profile and add at the end of the file, in my case "export PATH_TO_FX=/home/microcut/javafx-sdk-11.0.2/lib". Once I did this, I checked the PATH_TO_FX (after a reboot) in terminal using echo $PATH_TO_FX.

I wrote a small bash script called first.sh, using the nano editor.

#!/bin/sh
sudo java -jar --module-path $PATH_TO_FX --add-modules javafx.controls /home/microcut/serialtest.jar

(I actually don't need to use the sudo command, but left it in)

Also

Please note, that when I installed this linux distro (ubuntu mate 20-stripped version)., I just used the default java jdk and jre on it, which turns out to be java 11.0.2

sudo apt install default-jre
sudo apt install default-jdk

After I saved the bash script first.sh I then made the first.sh bash script executable using:

chmod +x first.sh

I then tested the bash script from terminal by just typing first.sh to test - worked fine (by the way I also have a script for the B4Jbridge using the same method, but you need to be in terminal to use it).

I then used launcher to (right click on desktop) create a desktop launcher for the application, to make sure it executed from the desktop properly (no terminal needed).

I then added using Menu, Preferences, Startup Applications,(from the desktop) and created a startup application using the same script file.

I set my desktop background to our corporate logo, and auto hid the both top and bottom toolbars.
I then edited the startup script to get rid of the unbuntu splash screen etc.
So now when I turn on the system, it launches the B4X application natively and looks very custom.

One thing I forgot to mention is that unfortunately, when you run sudo, it will ask you for a password, this can be cumbersome, so you can get rid of this requirement doing the following:

sudo visudo
This will open the vi text editor for sudo, at the bottom of the file, I added in my case:
microcut ALL=(ALL) NOPASSWD: ALL
and saved it.

Now you can run sudo without the password prompt.

This is a bit rambling, I admit, and I hope this may help or point someone in the proper direction for their system.

I personally am beginning to love the linux environment, and I saw some posts that talked about being able to run the B4J ide in this environment, at some point when I have time I would like to look into that.
 
Upvote 0
Top