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,360
Last edited:

miga

Member
Licensed User
Longtime User
May I create Mac installer (dmg) on Windows? I have done my application and want to distribute it in both formats.
 

Cableguy

Expert
Licensed User
Longtime User
I have a multi .jar file app... basically a main app, and a config app... is it possible to combine both the jar into the same installer?
is it possible to have a "run after install" option during install?
 

Nokia

Active Member
Licensed User
Longtime User
do you have to have the inno setup on the mac osx machine or just he JDK?

will the bundles folder be in the same folder as the Jar file?
 

aaronk

Well-Known Member
Licensed User
Longtime User
When I try and create the installer I get it coming up saying 'Error Parsing Manifest file.'

I installed innosetup-5.5.9 on my computer.

Running this on windows 10 on a VM on a Mac. (same computer I am using B4J on)

Any ideas on what could cause this to happen ?

When I run my server.jar file it runs fine, just can't create the installer file.

upload_2016-10-27_16-48-28.png
 

Nokia

Active Member
Licensed User
Longtime User
You don't need inno setup on the Mac.

You can see an example of a dmg package here: www.b4x.com/b4j/files/GoogleMapsExample.dmg

when I run the B4JPackager both your original and my modified, they do not produce a bundle. it just opens up a window with my app and a folder for applications.

on your original it seems to close and tries to open up again. but can't and the first time it opened it ask me if I wanted to install xcode. do you know if I need anything else to install?
 

alienhunter

Active Member
Licensed User
Longtime User
Hi
I get this error , it worked i in earlier java 1.80.60 , now 101
any clue why
thanks

(IOException) java.io.IOException: java.lang.IllegalArgumentException: MALFORMED
pack.jpg


I narrowed it down to archiver , it does not unzip the manifest for some reason


B4X:
        Dim archiver As Archiver
        If archiver.UnZipFiles(txtJar.Text,"",workingFolder, Array As String("META-INF/MANIFEST.MF"), "") <> 1 Then
            cutils.ShowNotification2("", "Manifest file not found. Make sure that the jar file was compiled in release mode.", _
                cutils.ICON_ERROR, MainForm)
            Return
        End If
 
Last edited:

alienhunter

Active Member
Licensed User
Longtime User
What is the value of txtJar.Text ?

I did not checked this will check , I downloaded your example again yesterday
and it was the same error , but if i unzip the jar and place the meta folder in place it works
i did not noticed this unitl i updated the jdk/jre from 60 to 101
 

alienhunter

Active Member
Licensed User
Longtime User
What is the value of txtJar.Text ?
Program started.

hi here it is
txtJar.Text=
C:\MASTER ROOT\001-JAVA-WINDOWS_DEVELOPMENT\001-JAVA-SOURCECODES\001-JAVA-SUITE\JAVA_MANAGMENT-001_VERSION_1_006\Objects\xxxxx_app_suite.jar
(IOException) java.io.IOException: java.lang.IllegalArgumentException: MALFORMED



Did not worked even if i shortened the path, only if i disabled the archiver and copy
meta- inf manually

settings.txt
#Wed Nov 09 15:13:05 EST 2016
version=1.000
name=Chloe
icon=C\:\\Windows\\Folder.ico
packager=C\:\\Program Files (x86)\\Java\\jdk1.8.0_101\\bin\\javapackager.exe
jar=C\:\\MASTER ROOT\\JAVA_MANAGMENT-001_VERSION_1_005\\Objects\\xxxxx_app_suite.jar
title=Chole
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
As you found out it fails to unzip the jar file for some reason.

The truth is that this step is not very important. You can explicitly set appClass and comment the problematic code:
B4X:
'     Dim archiver As Archiver
'     If archiver.UnZipFiles(txtJar.Text, "",workingFolder, Array As String("META-INF/MANIFEST.MF"), "") <> 1 Then
'       cutils.ShowNotification2("", "Manifest file not found. Make sure that the jar file was compiled in release mode.", _
'         cutils.ICON_ERROR, MainForm)
'       Return
'     End If
'     Dim manifest As String = File.ReadString(workingFolder, "META-INF/MANIFEST.MF")
'     Dim m As Matcher = Regex.Matcher2("JavaFX-Application-Class:\s*(.*)$", Regex.MULTILINE, manifest)
'     Dim appClass As String
'     If m.Find Then
'       appClass = m.Group(1)
'     Else
'       cutils.ShowNotification2("", "Error parsing manifest file.", _
'         cutils.ICON_ERROR, MainForm)
'       Return
'     End If
     Dim appClass As String= "chloe.integrity.main"

I tested it and it works. Note that you need to make some changes in your code and use File.DirData instead of File.DirApp which is read-only once your app is installed under Program Files (for further discussion please start a new thread).
 

alienhunter

Active Member
Licensed User
Longtime User
Hi Erel
thank you for your time and advice , still work in progress some of the modules i will take your advice and correct this
AH
 

Toley

Active Member
Licensed User
Longtime User
I need to make a package including external driver too. Is this tool can do it?
 
Status
Not open for further replies.
Top