B4J Tutorial B4JPackager11 - the simplest way to distribute UI apps

Status
Not open for further replies.
Better to start with the integrated packager: https://www.b4x.com/android/forum/t...-way-to-distribute-standalone-ui-apps.117880/
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:

SS-2018-11-28_16.43.14.png


- run.exe is the executable (starting from v1.14 the executable name is based on the jar name). The executable file depends on the other folders. You can distribute the executable and the folders and it will work without any other dependencies.
- 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. The installer will be a single.
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.
- AdditionalModuleInfoString - A string that will be added to the module.info file. This is required in some cases such as with jPOI: https://www.b4x.com/android/forum/threads/105311/#content

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:
B4X:
<java 11>\bin\java -jar B4JPackager11.jar <json file>

The json file should look like this:
B4X:
{
   InputJar: "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:
B4X:
{
   InputJar: "C:/Users/H/Documents/B4X/X2/Angry Birds/B4J/Objects/AngryBirds.jar",
   ExcludedModules: []
}

Platforms

You must build the package on the target platform.
Windows - Java 11+ should already be installed. Note that Java 11+ is 64 bit only.
Mac - use MacSigner https://www.b4x.com/android/forum/threads/macsigner-building-notarized-mac-packages.130890/#content
Linux - https://www.b4x.com/b4j/files/java/linux_jdk-14.0.1.zip

Notes

- All files in the packager temp folder are deleted when it runs.
- MediaPlayer will fail to play files from File.DirAssets. Copy them when the program starts.

Updates

- V1.21 - Integrated version. Adds support for Java 14.
- V1.15 - Updated the inno script template based on Peter's suggestions: https://www.b4x.com/android/forum/t...-the-inno-setup-file-by-default-maybe.114539/
- V1.14 - The executable name is set to be the same as the input jar name. Internally it also creates a copy of javaw.exe with the same name. This sets the process name in task manager. Note that the description will still be "OpenJDK ...".
- V1.13 - Allows configuring VM arguments. It can be done with the VMArgs global variable or a VMArgs key in the json file.
- V1.12 - Skips automatic inclusion for services based on inner classes as it breaks the jdeps tool.
- V1.11 - Adds a check that InputJar points to a jar file.
- V1.10 - Adds support for command line arguments. Usage example: https://www.b4x.com/android/forum/threads/associating-files-with-your-app.106984/
(Currently only supported on Windows)
- V1.05 - Fixes the "failed to delete temp folder" issue when the folder is open in Windows Explorer.
- V1.04 - New AdditionalModuleInfoString field. This is required when packaging for an app that uses jPOI.
- v1.02 - Configures the Inno Setup script to 64 bit.
- v1.01 - Fixes a localization issue.
 

Attachments

  • B4JPackager11.zip
    13 KB · Views: 2,974
Last edited:

tuhatinhvn

Active Member
Licensed User
Longtime User
i have some files on folder File.DirApp , when use this packager where is these file should be copied?
 

jmon

Well-Known Member
Licensed User
Longtime User
It works great. I suggest adding an option to add additional files. This way the installer can include other files and subdirectories. The simplest is to have 1 folder that will include all the files that need to be copied to the application directory.
In Process_Globals:
B4X:
Sub Process_Globals
    '...
    Private AdditionalFolder As String = "C:\AdditionalFolder\"
    'non configurable variables:
    '...
End Sub

In Start (I commented the existing lines):
B4X:
Sub Start
    '...
    'Wait For (BuildRunner) Complete (Success As Boolean)
    Wait For (CopyAdditionalFolder) Complete (Success As Boolean)
    'Wait For (OpenExplorer) Complete (Success As Boolean)
    '...
End Sub

And then adding those 2 functions:
B4X:
Private Sub CopyAdditionalFolder As ResumableSub
    If AdditionalFolder <> "" Then
        CopyFolder(AdditionalFolder, File.Combine(TempFolder, "\build"))
    End If
    Return True
End Sub

Private Sub CopyFolder(Source As String, targetFolder As String)
    If File.Exists(targetFolder, "") = False Then File.MakeDir(targetFolder, "")
    For Each f As String In File.ListFiles(Source)
        If File.IsDirectory(Source, f) Then
            CopyFolder(File.Combine(Source, f), File.Combine(targetFolder, f))
            Continue
        End If
        File.Copy(Source, f, targetFolder, f)
    Next
End Sub

The InnoSetup file doesn't need to be modified, as it's already including the recusrsivesubdirs flag:
B4X:
[Files]
Source: build\*; DestDir: {app}; Flags: ignoreversion recursesubdirs createallsubdirs
 

Woinowski

Active Member
Licensed User
Longtime User
Hello Erel, is there any news on the improved startup executable? (no terminal window)

Hi Erel,

my bash is a little rusty (not having used it for nearly 20 years), but I have a rough idea to solve this "get rid of window" with this bash line

B4X:
exit & \bin\java -jar foo.jar

"\bin\java -jar foo.jar" stands for whatever you need to start the jar file. Basic idea is to fork the jar execution and then exit the shell. If this does not work, than at least the fork direction might help.
 

Mmilo1971

Member
Hello,
I am using B4JPackager11 and in the log window I can see:

...
Waiting for debugger to connect ....
Program started.
B4JPackager11 Version 1.13
InputJar: C:\\Users......\Graduatoria.jar (my file)
Running: C:\\Users\User\Desktop\B4JPAC-1\Objects\temp\FindDos.Path.exe
Folder not found:


and after the program stop.

Where I am wrong?
Thank you
Massimiliano
 

Mmilo1971

Member
I did right click and choose the menu item "toggle brekpoint", in debug mode it stops and the line become Yellow and in the log window I see the messages above except the "Folder not found". Going on the error is the same.

I added:
B4X:
Log (JavafxJmods)
Log (JavaFXLibs)

And
JavafxJmods seems to be void ...it doesn't return anything
JavaFXLibs return C:\Program Files\Java\jdk-11.0.4\bin\..\javafx\lib

Thank you
 
Last edited:

Mmilo1971

Member
:):):):D:D:D:p:p:p

Yeaaaahhh … YOU WAS RIGHT …… my fault was downloading Java from the official website.

PS: I discovered B4X searching a software to develop Android App …. so after some practice where I would translate some Python programs I wrote for my wife … I will for sure buy B4A …. I already have bought the BIG Book o_O .. next step will be the software.

Thank you again for your help.
Massimiliano
 

Carlos marin

Active Member
Licensed User
Longtime User
Erel I'm getting this error on line 130 :eek::(

Running: C:\Users\CARLOS~1\Desktop\B4JPAC~1\Objects\temp\FindDosPath.exe
Folder not found:
 

MrKim

Well-Known Member
Licensed User
Longtime User
This tool is designed for Java 11+. You should use the previous B4JPackager tool for older versions of Java.
I am confused. I open the Java Control panel and it says I am Java Version 8 Update 231 (build 1.8.0_231-b11) and am up to date. Where is 11?
Also, What is OpenJDK 11 and how do I find out if it is installed and what version it is? I found some info online that said type javac -version. that returns javac 1.8.0_131. But that does not seem right.
 
Status
Not open for further replies.
Top