B4J Tutorial UI apps packaging - self contained installers

Status
Not open for further replies.
It is recommended to use B4JPackager11: Integrated B4JPackager11 - The simple way to distribute standalone UI apps

B4J Packager is a small utility that uses javapackager to create a single file installer for Mac or Windows, that includes the app files and the Java runtime.

This means that from the end user perspective your app doesn't depend on any additional runtime. It makes deployments very simple.
The installer size will be around 40mb as it includes the JRE.

SS-2015-08-02_17.14.48.png


The Windows installer (exe) is built on a Windows computer and the Mac installer (dmg) is built on a Mac computer.
You need to install Inno Setup on the Windows computer: http://www.jrsoftware.org/isinfo.php

You can either run the attached source code from the IDE or download the jar file: www.b4x.com/b4j/files/B4JPackager.jar

The source code depends on the following additional libraries: Archiver (B4A library) and jControlFX

Using this tool is quite simple. First you need to set the path to javapackager.
On Windows the path will be similar to:
C:\Program Files\Java\jdk1.8.0_51\bin\javapackager.exe
On Mac:
/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/bin/javapackager

Compile your app in release mode and then set the path to the Jar file and fill the other fields.
The icon on Windows is an ico file and on Mac is an icns file.

Click on the Build button. The building process can take a minute or two.
The installer will be created under the bundles folder (the folder will be opened).

Notes & tips:

1. Make sure to test your app after it is installed. It will be installed under Program Files.
Program Files is a read-only folder. Any attempt to write to File.DirApp will fail (you should use File.DirData instead).

2. javapackager documentation:
Windows - https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javapackager.html#BGBIJBHF
Linux / Mac - https://docs.oracle.com/javase/8/docs/technotes/tools/unix/javapackager.html

3. It is recommended to run the packager from the IDE (at least in the beginning) as it prints important information in the logs.
You can also run it from the command line with: java -jar B4JPackager.jar
4. The installers will use the app package name to identify the app. Make sure to change it from the default value. Otherwise all applications will be installed in the same folder.
5. Java 9 is currently not supported. Make sure that both B4J and the path to javapackager point to Java 8.
6. If running on a Mac then you probably should change the package to pkg. See this discussion: https://www.b4x.com/android/forum/t...staller-dmg-failed-to-produce-a-bundle.87897/

Change log:

v1.50

- Adds support for newer versions of Java 8.
- javapackager is run in verbose mode.
- The logs are updated while the process is running.
 

Attachments

  • B4J Packager.zip
    4.7 KB · Views: 2,527
Last edited:

Aristide

Member
@Erel

I use your packager. All is ok for building exe on Windows 7 - 64.
When i use this install on Windows 10 32, there is an error :



The install seems to be ok, but the program abort.

Ps : I use the link of your packager in the first page.


Add : I execute the installer on the same PC where I build it. And it's OK.


Plus : When i try to execute with the java command on the same pc that abort install

 
Last edited:

Swissmade

Well-Known Member
Licensed User
Longtime User
Why you don't use Launch4j is working perfect if you like to create Exe Files.
 

m4.s

Member
Licensed User
Longtime User
Hello Erel,

I have downloaded the B4JPackager.jar (many times over) but I always just get a blank/empty window/form when it executes/opens - as shown below:

upload_2017-3-16_0-8-58.png



I also always get the same after I install and run your GoogleMaps Example [JRE bundled] application EXE:

upload_2017-3-16_0-9-27.png



Do you have any explanation for this? I'm on Windows 10 Home (64-bit), with jre1.8.0_111 (and jdk1.8.0_102) 64-bit Java installed.


Further, when I extract your provided B4JPackager.zip, I can open the B4J project code file but am immediately advised that I'm missing the Archiver library; which only seems available if one has purchased a B4A license; which I've not as I don't develop Android apps. That does not seem right, or is that true? {You don't explicitly state that one page 1 of this thread.}


Thanks, as always, for your assistance.
 

m4.s

Member
Licensed User
Longtime User
Thanks Erel. Your new jar fixed my blank/empty B4J Packager window problem; and I was then able to bundle my application with the JRE files successfully.

As expected though, even after downloading and installing again, your packaged GoogleMaps example application still opens to a blank/empty window. I suspect maybe you'd need to repackage it with the [Windows 10-specific?] fix you made to the jar...? There's certainly no urgency/rush re: this if so (just wanted to report).

However, I still need to know if I must purchase a B4A license just to get the Archiver library -- so that I can modify and run the B4J Packager project code in the B4J IDE, in order for me to pass the javapackager parameters necessary for my application's custom packaging and installer requirements.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
As expected though, even after downloading and installing again, your packaged GoogleMaps example application still opens to a blank/empty window. I suspect maybe you'd need to repackage it with the [Windows 10-specific?] fix you made to the jar...?
You are correct. However it is only an example of the installer.

It should be simple to remove the dependency on Archiver library. It is only used to extract the manifest file and find the package name. You can explicitly set appClass instead.
 

m4.s

Member
Licensed User
Longtime User
Thank you Erel. As always, you're right (and I should have tried that first).

My locally edited B4J Packager project is compiling and running fine from IDE for me now!
 
I try to run the code but it tells me :
B4J version: 5.51
Parsing code. Error
Error parsing program.
Error description: Unknown type: archiver
Are you missing a library reference?
Occurred on line: 112 (Main)
Dim archiver As Archiver
What should I do?
 

Lahksman

Active Member
Licensed User
Longtime User
I try to run the code but it tells me :
B4J version: 5.51
Parsing code. Error
Error parsing program.
Error description: Unknown type: archiver
Are you missing a library reference?
Occurred on line: 112 (Main)
Dim archiver As Archiver
What should I do?

You need to get the B4A archiver library as stated in the first post.
The source code depends on the following additional libraries: Archiver (B4A library) and jControlFX
 
Status
Not open for further replies.
Top