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:
Write a detailed algorithm on how to build an AppImage package for Linux (run from any directory, i.e. relocatable AppImage) for an application named "MyB4JApp" written in Java using JavaFX. All java library files are located in the "~/myb4japp/jdk14 " directory. The binary file is located in the "~/myb4japp/myb4japp.jar"

Reply:

1. Preparing the AppDir:

  • Create a directory ~/myb4japp/AppDir. This will be the root directory of your AppImage.
  • Inside AppDir, create the following directories:
    • usr/bin: For the executable file.
    • usr/lib: For the JRE and application libraries.
    • usr/share/applications: For the .desktop file, which will allow integration with the desktop environment.
    • usr/share/icons: For the application icon.
2. Copying Files:

  • Copy ~/myb4japp/myb4japp.jar to ~/myb4japp/AppDir/usr/bin/myb4japp.jar.
  • Copy the contents of ~/myb4japp/jdk14 to ~/myb4japp/AppDir/usr/lib/jdk14.
3. Creating the AppRun Script:

Create a file ~/myb4japp/AppDir/AppRun with the following content:

bash

#!/bin/bash
export JAVA_HOME="$APPDIR/usr/lib/jdk14"
export PATH="$JAVA_HOME/bin:$PATH"
export APP_DIR="$APPDIR/usr/lib/myb4japp" # Assuming your app-specific libraries are here

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


Make AppRun executable:

bash

chmod +x ~/myb4japp/AppDir/AppRun

4. Creating the .desktop File:

Create a file ~/myb4japp/AppDir/usr/share/applications/myb4japp.desktop with the following content:


[Desktop Entry]
Type=Application
Name=MyB4JApp
Exec=AppRun
Icon=myb4japp
Categories=Development;

5. Adding an Icon:

Create an icon for your application (e.g., myb4japp.png or myb4japp.svg) and place it in ~/myb4japp/AppDir/usr/share/icons/. Ensure the icon filename matches the Icon value in the .desktop file.

6. Generating the AppImage:

Download appimagetool from the official website. Then, execute the following command in the ~/myb4japp directory:

bash

appimagetool AppDir

This will create a file myb4japp-x86_64.AppImage (architecture may vary) in the ~/myb4japp directory.

7. Testing and Distribution:

Make the AppImage executable:

bash

chmod +x myb4japp-x86_64.AppImage

Now you can run your application by double-clicking the AppImage file or running it from the terminal. You can distribute this AppImage file without requiring installation.

Additional Recommendations:

  • Reducing AppImage Size: You can use jlink to create a minimal JRE containing only the necessary modules for your application. This will significantly reduce the AppImage size. 1
  • Using linuxdeployqt: If your application uses Qt libraries, you can use linuxdeployqt to automatically include the required dependencies.
  • Compression: Consider using compression inside the AppImage to further reduce its size.
This algorithm provides a basic approach to AppImage creation. Depending on the complexity of your application, additional steps might be required. It's recommended to consult the AppImage documentation for more detailed information.

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
...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
Top