B4J Tutorial Integrated B4JPackager11 - The simple way to distribute standalone UI apps

Status
Not open for further replies.
B4JPackager11 is a utility written in B4J that uses the underlying Java tools to create a standalone package that doesn't depend on any other software being installed.
It works with OpenJDK 11 and OpenJDK 14.
Starting from B4J v8.30 it is integrated in the IDE and available under Project - Build Standalone Package.
External tool: https://www.b4x.com/android/forum/t...lest-way-to-distribute-ui-apps.99835/#content

Example:

Shw8yVDjRi.gif


The output of this tool looks like this:

explorer_fa8Z3lAQP3.png


You need to distribute the executable together with the 4 folders.
The run_debug.bat batch file is useful to test the program and see the logs.

An Inno Script template is created in the parent folder. You can use it together with Inno Script to build a single file installer.

The integrated packager creates a Windows package. You can however use the external tool with the generated json file (in the project folder) to create Linux and Mac packages.

The packager supports all kinds of settings. You can set them with the new #PackagerProperty attribute.

For example to set the icon file, assuming that the ico file is in the Files tab and is named turtle.ico:
B4X:
#PackagerProperty: IconFile = ..\Files\turtle.ico
Also set the executable name:
B4X:
#PackagerProperty: IconFile = ..\Files\turtle.ico
#PackagerProperty: ExeName = Turtle
Note that this will set the executable icon. Set the form icon with the designer. The form icon should be a regular image file (png, jpg, ...).

Tips and special cases

  1. If using jPOI library then you must reference XLUtils.
  2. If using WebView or HtmlEditor add:
    B4X:
    #PackagerProperty: IncludedModules = javafx.web
  3. If using jGoogleMaps add:
    B4X:
    #PackagerProperty: IncludedModules = javafx.web
    #PackagerProperty: AdditionalModuleInfoString = exports com.lynden.gmapsfx.javascript.event;
    There is an issue with Java 14 and Google Maps. Use Java 11 for now if using jGoogleMaps.
  4. You can use #CustomBuildAction with the new After Packager step to copy files after the package is built. The default target folder should be: temp\build\bin\
  5. If using jSerial put the attached jssc.dll file in the project folder and add:
    B4X:
    #CustomBuildAction: After Packager, %WINDIR%\System32\robocopy.exe, ..\ temp\build\bin\ jssc.dll
    Note that it is a Windows 64 bit dll.
    MacSigner instructions: https://www.b4x.com/android/forum/threads/mac-and-jssc.135823/post-859095
  6. Each PackagerProperty key should appear at most once. So for example if using both WebView and jPOI add: #PackagerProperty: IncludedModules = jdk.charsets, javafx.web
    Starting from B4J 9.00, the same property can appear multiple times and the values will be appended.
  7. If you get an error that looks like: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure, add:
    B4X:
    #PackagerProperty: IncludedModules = jdk.crypto.ec
  8. If using jWebSocketClient then you need to add:
    B4X:
    #PackagerProperty: AdditionalModuleInfoString = uses org.eclipse.jetty.websocket.common.RemoteEndpointFactory;
  9. If you want to copy the generated build to a different folder (C:\Users\H\Downloads\test for example):
    B4X:
    #CustomBuildAction: After Packager, %WINDIR%\System32\robocopy.exe, /MIR temp\build\ C:\Users\H\Downloads\test
    Warning : the destination folder will be deleted recursively.
  10. A json file named packager.json is created in the Objects folder. You can use it to run the external packager tool, for example to build Mac or Linux packages.
  11. Steps to automatically build the setup file with Inno Script:
    • Move the generated InstallerScript-template.iss file to the project folder and rename it to InstallerScript.iss.
    • Edit the script, change the app name, publisher and other fields as needed. You also need to update two paths as explained in post #3.
    • Put the icon file in the project folder.
    • Add this attributes:
      B4X:
      #PackagerProperty: IconFile = ..\turtle.ico
      #CustomBuildAction: After Packager, C:\Program Files (x86)\Inno Setup 6\Compil32.exe, /cc ../InstallerScript.iss
    • Output after choosing Project - Build standalone package:

      explorer_ZR0Ey83790.png

    • Note that the AppId field shouldn't be changed after you distribute your app.
  12. By default, not all of the localization data is added to the package. This can cause for example, the dates to appear in English even when the default locale is non-English. You can add the missing data with:
    B4X:
    #PackagerProperty: IncludedModules = jdk.localedata
    It will add about 9mb to the built package.
    (Don't miss tip #6 if you need to add multiple modules.)
 

Attachments

  • jssc.zip
    38 KB · Views: 966
Last edited:

Dadaista

Active Member
Licensed User
Longtime User
Hi
If only supports jpg, png or gif.... then "build stand alone package" is not working 'cause, "build stand alone package" fails with .png files
 

Revisable5987

Member
Licensed User
Just tried to build stand alone package and it works fine.

Probably best to start a new post and upload a sample project.
I'll keep my eye out for it
 

Dadaista

Active Member
Licensed User
Longtime User
Thank you @kgcarpenter
... My project has more than 7000 lines... I can not upload a piece of the project.
I keep trying to make the package with ".. stand alone.." but.... with b4jPackager I have no problem.
Thank you very much!!!
 

Revisable5987

Member
Licensed User
Thank you @kgcarpenter
... My project has more than 7000 lines... I can not upload a piece of the project.
I keep trying to make the package with ".. stand alone.." but.... with b4jPackager I have no problem.
Thank you very much!!!
Post the error then so I can see what the issue could be.
Happy to help but you really should start a new thread now.

Thanks
 

Dadaista

Active Member
Licensed User
Longtime User
Hi
Right now, no errors in log :rolleyes:
Only... the Icon is not showed in the top left in window of app :mad:
English is not my languaje and I can not explain the issue as I would in my languaje... that is the reason no new thread :confused:... hard to explain it for me

One tip..
This is not working for me
B4X:
#CustomBuildAction: After Packager, C:\Program Files (x86)\Inno Setup 6\Compil32.exe, /cc ..\Caja Venta.iss

But this is working
B4X:
#CustomBuildAction: After Packager, C:\Program Files (x86)\Inno Setup 6\Compil32.exe, /cc "..\Caja Venta.iss"

Double quotes in .iss file path !!!!!!!

Thank you so much for your help @kgcarpenter... really!!!!!!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I keep trying to make the package with ".. stand alone.." but.... with b4jPackager I have no problem.
It is the same packager.

There are two different icons:
- Executable icon is set with: #PackagerProperty: IconFile = ..\Files\turtle.ico
The file must be an ICO file.
- Form icon is set with the designer and it should be a regular image file (png, jpg, ...)
 

DavideV

Active Member
Licensed User
Longtime User
Hello,
I added the .ico file with the directive:
#PackagerProperty: IconFile = ..\files\shutdown.ico.
The executable created in the build folder shows the correct icon, but when I move all files & folders to another location, the executable icon goes back to the default B4J one's..
On the right: the build folder, on the left: the folder where I moved the files...
Am I doing something wrong?

Thanks
Cattura.PNG
 

R D Boozer

Member
Licensed User
Erel, I noticed on the original page for the external tool that you have added a download link for OpenJDK 14 for Mac OS. Where is the download link for OpenJDK 14 for Linux?
 

Jorge M A

Well-Known Member
Licensed User
Longtime User
Notes
  • The Alpine Linux build previously available on this page was removed as of the first JDK 14 release candidate. It’s not production-ready because it hasn’t been tested thoroughly enough to be considered a GA build. Please use the early-access JDK 15 Alpine Linux build in its place.
  • If you have difficulty downloading any of these files please contact jdk-download-help_ww@oracle.com.
 

IndieDev

Active Member
Licensed User
Creating Setup file in Inno Setup Compiler displays this warning.
(using the generated "InstallerScript-Template.iss" file )

Warning: Constant "pf" has been renamed. Use "commonpf" instead or consider using its "auto" form.

Any changes required from my side?

Inno Setup Compiler 6.0.4
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
By the way, the post B4jPackager has the following typo. (Linix)
Fixed. Thank you.

Creating Setup file in Inno Setup Compiler displays this warning.
(using the generated "InstallerScript-Template.iss" file )

Warning: Constant "pf" has been renamed. Use "commonpf" instead or consider using its "auto" form.

Any changes required from my side?
No. I don't remember the exact reason for this warning however the current template will work properly.
 

IndieDev

Active Member
Licensed User
Fixed. Thank you.


No. I don't remember the exact reason for this warning however the current template will work properly.

Yes. The template works fine. Thanks.

By the way, is there any way I can display my app icon in the Task Manager?
It currently displays a Java icon.
del.jpg


The app icon is correctly displayed in the Task Bar.
Screenshot (9).png


Have added the following in the Project Attributes.
#PackagerProperty: IconFile = ..\Files\icon.ico
 

IndieDev

Active Member
Licensed User
Creating Setup file in Inno Setup Compiler displays this warning.
(using the generated "InstallerScript-Template.iss" file )

Warning: Constant "pf" has been renamed. Use "commonpf" instead or consider using its "auto" form.

Any changes required from my side?

Inno Setup Compiler 6.0.4

In the "InstallerScript-Template.iss" file, I changed this line: DefaultDirName={pf}\{#MyAppPublisher}\{#MyAppName}

To: DefaultDirName={commonpf}\{#MyAppPublisher}\{#MyAppName}

Compiled without any warnings and product installed fine.

(Nudge from Inno Setup GIT revision page . Section: 6.0.0-beta )
 
Status
Not open for further replies.
Top