B4J Question Package for Linux desktop

aeric

Expert
Licensed User
Longtime User
Anyone has built any distributable desktop package for Linux desktop from jar or files built by B4JPackager11 ?

For Debian based or Ubuntu, it uses .deb and RedHat uses .rpm and so on.

If yes, can anyone share a tutorial explain in easy way how to accomplish it?
 

OliverA

Expert
Licensed User
Longtime User
Many packages have to be installed with sudo. The home directory is usually ~. If that works in the configuration files, idk.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Actually I have successfully created the deb file using dpkg.
The problem is many directories are not writable.
The best writable directory is home/USER but I won't know what is the user's directory name.
The user's directory name(install-dir) is determined by yourself, and you can also do anything you want to do during installing process by script,including with user interaction etc
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
The user's directory name(install-dir) is determined by yourself, and you can also do anything you want to do during installing process by script,including with user interaction etc
Thanks for your suggestion.
It seems I need to learn more on the script.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Hi, @aeric
Maybe any progress in Linux packages building ?
Now i'm also interested in both package types, DEB and RPM.

But maybe more perpective is AppImage...
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
Hi, @aeric
Maybe any progress in Linux packages building ?
Now i'm also interested in both package types, DEB and RPM.

But maybe more perpective is AppImage...
I didn't explore further since then but when I suddenly want to do it, I may ask AI chatbot. You may help me/us to do the research if you have time.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
To create a distributable Linux package ([code single].deb[/code] or [code single].rpm[/code]) from a B4J (Basic4Java) JAR file, follow these steps:



---



## 1. Prepare Your B4J Application

Before packaging, ensure:

- Your B4J app is compiled into a JAR file.

- Any necessary dependencies (e.g., Java runtime) are included.

- Your app can be executed using:

```bash

java -jar yourapp.jar

```



If you need your app to run without requiring users to install Java, consider bundling it with a JDK runtime using jlink or [code single]jpackage[/code].



---



## 2. Create a [code single].deb[/code] (Debian/Ubuntu) Package

[h3]2.1 Set Up Folder Structure[/h3]
Create a directory for your package:

B4X:
mkdir -p myapp_1.0/usr/local/bin

mkdir -p myapp_1.0/DEBIAN
Place your JAR file inside [code single]usr/local/bin/[/code]:

B4X:
cp yourapp.jar myapp_1.0/usr/local/bin/
[h3]2.2 Create a Startup Script[/h3]
Create a launcher script ([code single]myapp[/code]) in [code single]usr/local/bin/[/code]:

B4X:
nano myapp_1.0/usr/local/bin/myapp
Add:

B4X:
#!/bin/bash

java -jar /usr/local/bin/yourapp.jar
Make it executable:

B4X:
chmod +x myapp_1.0/usr/local/bin/myapp


[h3]2.3 Create [code single]control[/code] File[/h3]
Create a control file:

B4X:
nano myapp_1.0/DEBIAN/control
Example:

B4X:
Package: myapp

Version: 1.0

Architecture: all

Maintainer: Your Name <your@email.com>

Description: My B4J Application

Depends: default-jre
Ensure dependencies (like Java) are listed under [code single]Depends[/code].



[h3]2.4 Build the [code single].deb[/code] Package[/h3]
Run:

B4X:
dpkg-deb --build myapp_1.0
Now you have [code single]myapp_1.0.deb[/code], which can be installed using:

B4X:
sudo dpkg -i myapp_1.0.deb


---



## 3. Create an [code single].rpm[/code] (RedHat, Fedora, CentOS) Package

[h3]3.1 Install [code single]rpm-build[/code][/h3]
Ensure [code single]rpm-build[/code] is installed:

B4X:
sudo dnf install rpm-build
[h3]3.2 Set Up Directory Structure[/h3]
B4X:
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

mkdir -p ~/rpmbuild/BUILDROOT/myapp-1.0-1.x86_64/usr/local/bin
Move your JAR and script:

B4X:
cp yourapp.jar ~/rpmbuild/BUILDROOT/myapp-1.0-1.x86_64/usr/local/bin/

cp myapp ~/rpmbuild/BUILDROOT/myapp-1.0-1.x86_64/usr/local/bin/
[h3]3.3 Create a [code single].spec[/code] File[/h3]
Create [code single]myapp.spec[/code]:

B4X:
nano ~/rpmbuild/SPECS/myapp.spec
Example:

B4X:
Name: myapp

Version: 1.0

Release: 1%{?dist}

Summary: My B4J Application

License: MIT

Source0: %{name}-%{version}.tar.gz

BuildArch: noarch

Requires: java

%description

This is a B4J application.

%install

mkdir -p %{buildroot}/usr/local/bin

cp %{_sourcedir}/yourapp.jar %{buildroot}/usr/local/bin/

cp %{_sourcedir}/myapp %{buildroot}/usr/local/bin/

chmod +x %{buildroot}/usr/local/bin/myapp

%files

/usr/local/bin/yourapp.jar

/usr/local/bin/myapp
[h3]3.4 Build the [code single].rpm[/code] Package[/h3]
Run:

B4X:
rpmbuild -bb ~/rpmbuild/SPECS/myapp.spec
Your [code single].rpm[/code] file will be in [code single]~/rpmbuild/RPMS/noarch/[/code].



Install it using:

B4X:
sudo rpm -i myapp-1.0-1.noarch.rpm


---



## 4. Alternative: Using [code single]jpackage[/code]

If you're using Java 14+, [code single]jpackage[/code] can generate a [code single].deb[/code] or [code single].rpm[/code] automatically:

B4X:
jpackage --type deb --input . --name myapp --main-jar yourapp.jar --main-class MainClass --app-version 1.0
For [code single].rpm[/code]:

B4X:
jpackage --type rpm --input . --name myapp --main-jar yourapp.jar --main-class MainClass --app-version 1.0
This approach handles dependencies and system integration more cleanly.



---



[h3]Conclusion[/h3]
If you want a simple approach, use dpkg-deb for [code single].deb[/code] and rpmbuild for [code single].rpm[/code]. If you need a professional package with an installer, jpackage is a better choice.



Would you like help automating this process?



To package your proprietary B4J software into a [code single].deb[/code] format while ensuring it can access SQLite, XML, and asset files, follow these steps:



---



## 1. Define Installation Structure

Your package should install:

- The JAR file in [code single]/opt/myapp/[/code]

- The SQLite database, XML files, and assets in [code single]/var/lib/myapp/[/code]

- A configuration directory in [code single]/etc/myapp/[/code]

- A launcher script in [code single]/usr/local/bin/[/code]

- A desktop shortcut in [code single]/usr/share/applications/[/code] (optional)



[h3]Recommended File Layout[/h3]
B4X:
/opt/myapp/yourapp.jar # Main B4J JAR file

/var/lib/myapp/data.sqlite # SQLite database

/var/lib/myapp/config.xml # XML configuration

/var/lib/myapp/assets/ # Assets directory

/etc/myapp/config.properties # System-wide config (optional)

/usr/local/bin/myapp # Launcher script

/usr/share/applications/myapp.desktop # Menu shortcut (optional)


---



## 2. Prepare the Package Directory

Create the required directories:

B4X:
mkdir -p myapp_1.0/DEBIAN

mkdir -p myapp_1.0/opt/myapp

mkdir -p myapp_1.0/var/lib/myapp

mkdir -p myapp_1.0/etc/myapp

mkdir -p myapp_1.0/usr/local/bin

mkdir -p myapp_1.0/usr/share/applications


---



## 3. Copy Application Files

Place your B4J JAR file:

B4X:
cp yourapp.jar myapp_1.0/opt/myapp/
Copy SQLite, XML, and assets:

B4X:
cp data.sqlite myapp_1.0/var/lib/myapp/

cp config.xml myapp_1.0/var/lib/myapp/

cp -r assets/ myapp_1.0/var/lib/myapp/
Copy configuration files:

B4X:
cp config.properties myapp_1.0/etc/myapp/


---



## 4. Create a Launcher Script

Create [code single]/usr/local/bin/myapp[/code]:

B4X:
nano myapp_1.0/usr/local/bin/myapp
Add:

B4X:
#!/bin/bash

java -jar /opt/myapp/yourapp.jar
Make it executable:

B4X:
chmod +x myapp_1.0/usr/local/bin/myapp


---



## 5. Create a Desktop Shortcut (Optional)

Create [code single]myapp.desktop[/code]:

B4X:
nano myapp_1.0/usr/share/applications/myapp.desktop
Add:

B4X:
[Desktop Entry]

Name=MyApp

Exec=/usr/local/bin/myapp

Icon=/opt/myapp/icon.png

Type=Application

Categories=Utility;
If you have an app icon, copy it to [code single]/opt/myapp/icon.png[/code].



---



## 6. Create the [code single]control[/code] File

Create [code single]DEBIAN/control[/code]:

B4X:
nano myapp_1.0/DEBIAN/control
Example:

B4X:
Package: myapp

Version: 1.0

Architecture: all

Maintainer: Your Name <your@email.com>

Description: My Proprietary B4J Application

Depends: default-jre
If your app requires a specific Java version, modify [code single]Depends[/code]:

B4X:
Depends: openjdk-17-jre


---



## 7. Set File Permissions

Ensure files have correct ownership and permissions:

B4X:
chmod -R 755 myapp_1.0/

chmod -R 700 myapp_1.0/var/lib/myapp/ # Restrict user data access


---



## 8. Build the [code single].deb[/code] Package

Run:

B4X:
dpkg-deb --build myapp_1.0
This generates [code single]myapp_1.0.deb[/code].



---



## 9. Install and Test

To install:

B4X:
sudo dpkg -i myapp_1.0.deb
To verify:

B4X:
myapp


---



## 10. Handling User Configuration

- If your app needs user-specific data, store them in [code single]~/.config/myapp/[/code] instead of [code single]/var/lib/myapp/[/code].

- Modify your app to check for user config in [code single]~/.config/myapp/[/code] and fall back to [code single]/etc/myapp/[/code] if not found.



---



## Next Steps

- Do you want to add an uninstaller script?

- Do you need automatic database migration if users upgrade versions?

- Would you like to sign your package for extra security?



Let me know how you'd like to refine this!

(copied from ChatGPT)
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
I've also requested AI for AppImage creation:

Prompt:

Reply:


It needs to try !
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Hmm, i guess

"$JAVA_HOME/bin/java" -jar --module-path "$JAVA_HOME/javafx/lib:$APP_DIR/lib" --add-modules ALL-MODULE-PATH "$APPDIR/usr/bin/myb4japp.jar" "$@"

...should be just:

"$JAVA_HOME/bin/java" -jar --module-path "$JAVA_HOME/javafx/lib" --add-modules ALL-MODULE-PATH "$APPDIR/usr/bin/myb4japp.jar" "$@"
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Have you tested you are correct?
Ha! this AppImage tool (to produce my app's AppImage) is not executable under Mint21

Trying to make the regular DEB-package.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Have you tested
...should be just:
Yes, i was able to at last create .deb-package, without dependencies, JDK14 packed into the package, with .desktop icon.
But now app is partially usable due to errors that are found one by one under Linux in our XUI components.

Fully solved:

Excepting the COM-ports
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…