B4J Tutorial B4JPackager11 - the simplest way to distribute UI apps

Discussion in 'B4J Tutorials' started by Erel, Nov 28, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    B4JPackager11 is a B4J non-ui program that builds a package with your app jar and an embedded modularized Java runtime.

    It works with OpenJDK 11 and B4J v6.8+.

    Lets start with the output.

    It looks like this:


    run.exe is the executable. run_debug.bat starts the program with a console that shows the program output.
    It also creates a template Inno Setup script in the parent folder which you can use to build an installer.
    On Mac and Linux it doesn't create an executable. It instead creates a bash script file that can be used to start the program.

    There are two ways to run B4JPackager11:

    Directly from B4J - Start with this method.

    Just set the InputJar path and run it.

    There are several additional parameters that you can configure:
    - NetFrameworkCSC - Path to to the C# compiler which is part of .Net Framework.
    - IconFile - Path to the executable icon file (.ico file).
    - ExcludedModules - List of excluded modules. javafx.web is excluded by default. You need to remove it from the list if you are using WebView.
    - IncludedModules - List of included modules. Should be empty in most cases as the tool tries to discover the dependent modules automatically.

    Command line with a json file

    You can create a json file with the input jar and optionally other settings and run it from the command line:
    <java 11>\bin\java -jar B4JPackager11.jar <json file>
    The json file should look like this:
    "C:/Users/H/Documents/B4X/X2/Angry Birds/B4J/Objects/AngryBirds.jar"
    Use forward slashes as I did above.

    If you want to remove javafx.web from the excluded modules:
    "C:/Users/H/Documents/B4X/X2/Angry Birds/B4J/Objects/AngryBirds.jar",
       ExcludedModules: []

    You must build the package on the target platform.
    Windows - Java 11 should already be installed. Note that Java 11 is 64 bit only.

    OpenJDK 11 + OpenJFX 11 (SDK + jmods) - GPL + classpath exception license
    Mac - http://b4xfiles-4c17.kxcdn.com/b4j/mac_jdk-11.0.1.zip
    Linux - http://b4xfiles-4c17.kxcdn.com/b4j/linux_jdk-11.0.1.zip


    - All files in the packager temp folder are deleted when it runs.
    - You can use B4JPackager (not 11) for Java 8 builds: https://www.b4x.com/android/forum/threads/ui-apps-packaging-self-contained-installers.56854/


    - v1.01 - Fixes a localization issue.

    Attached Files:

    Last edited: Dec 2, 2018
  2. keirS

    keirS Well-Known Member Licensed User

    Would this work with the OpenJ9 JVM?
  3. Erel

    Erel Administrator Staff Member Licensed User

    This tool is designed for Java 11+. You should use the previous B4JPackager tool for older versions of Java.
  4. keirS

    keirS Well-Known Member Licensed User

    I am using Java 11 Open JDK. I am thinking of using the Eclipse/IBM JRE/JVM which is called OpenJ9.
  5. highflyer

    highflyer Member Licensed User

    Is there any way to avoid the opening of the terminal in nix and MacOS when running the packaged app ??
  6. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that it includes the JavaFX modules. It will be difficult to add them yourself.

    The current implementation is indeed not perfect on Mac and Linux. It will be improved.
    highflyer likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice