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

micro

Well-Known Member
Licensed User
Longtime User
Have you installed InnoSetup?
Yes, if you re-read carefully, with Javapackager.exe(64 bit) work fine and the packager is created only that on the win7 32bit not work, while with
Javapackager.exe(32 bit) run build and in a few second appears a window message "Package built successfully" but the folder is empty.
 

Douglas Farias

Expert
Licensed User
Longtime User
@Erel
exist a minimal version of mac to run this?
i m making a public app and i need to know the minimal version of mac to run my app with this installer.
thx
 

aaronk

Well-Known Member
Licensed User
Longtime User
When I run the source code from post 1 I get the following error in the IDE log:

B4X:
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: org/controlsfx/glyphfont/GlyphFont : Unsupported major.minor version 52.0
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at b4j.packager.main.<clinit>(main.java:17)
Caused by: java.lang.UnsupportedClassVersionError: org/controlsfx/glyphfont/GlyphFont : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:455)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:442)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:239)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 2 more
Exception in thread "main"

I have Inno Setup installed on my PC and I am running Windows 10.

I then thought I would try and run the B4JPacker.jar from the command prompt like: java -jar B4JPackager.jar

But that then returned the following:
B4X:
Program started.

main._process_globals (java line: 333)
java.lang.UnsupportedClassVersionError: org/controlsfx/glyphfont/GlyphFont : Unsupported major.minor version 52.0
  at java.lang.ClassLoader.defineClass1(Native Method)
  at java.lang.ClassLoader.defineClass(Unknown Source)
  at java.security.SecureClassLoader.defineClass(Unknown Source)
  at java.net.URLClassLoader.defineClass(Unknown Source)
  at java.net.URLClassLoader.access$100(Unknown Source)
  at java.net.URLClassLoader$1.run(Unknown Source)
  at java.net.URLClassLoader$1.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at b4j.packager.main._process_globals(main.java:333)
  at b4j.packager.main.initializeProcessGlobals(main.java:300)
  at b4j.packager.main.start(main.java:33)
  at com.sun.javafx.application.LauncherImpl$5.run(Unknown Source)
  at com.sun.javafx.application.PlatformImpl$5.run(Unknown Source)
  at com.sun.javafx.application.PlatformImpl$4$1.run(Unknown Source)
  at com.sun.javafx.application.PlatformImpl$4$1.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
  at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
  at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
  at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
  at com.sun.glass.ui.win.WinApplication$3$1.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)

Anyone know what I am missing ?
(I never get to see the form load on the screen and the above error happens as soon as the jar has run)
 

Douglas Farias

Expert
Licensed User
Longtime User
When I run the source code from post 1 I get the following error in the IDE log:

B4X:
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: org/controlsfx/glyphfont/GlyphFont : Unsupported major.minor version 52.0
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at b4j.packager.main.<clinit>(main.java:17)
Caused by: java.lang.UnsupportedClassVersionError: org/controlsfx/glyphfont/GlyphFont : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:455)
at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:442)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:239)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
... 2 more
Exception in thread "main"

I have Inno Setup installed on my PC and I am running Windows 10.

I then thought I would try and run the B4JPacker.jar from the command prompt like: java -jar B4JPackager.jar

But that then returned the following:
B4X:
Program started.

main._process_globals (java line: 333)
java.lang.UnsupportedClassVersionError: org/controlsfx/glyphfont/GlyphFont : Unsupported major.minor version 52.0
  at java.lang.ClassLoader.defineClass1(Native Method)
  at java.lang.ClassLoader.defineClass(Unknown Source)
  at java.security.SecureClassLoader.defineClass(Unknown Source)
  at java.net.URLClassLoader.defineClass(Unknown Source)
  at java.net.URLClassLoader.access$100(Unknown Source)
  at java.net.URLClassLoader$1.run(Unknown Source)
  at java.net.URLClassLoader$1.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at java.net.URLClassLoader.findClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at java.lang.ClassLoader.loadClass(Unknown Source)
  at b4j.packager.main._process_globals(main.java:333)
  at b4j.packager.main.initializeProcessGlobals(main.java:300)
  at b4j.packager.main.start(main.java:33)
  at com.sun.javafx.application.LauncherImpl$5.run(Unknown Source)
  at com.sun.javafx.application.PlatformImpl$5.run(Unknown Source)
  at com.sun.javafx.application.PlatformImpl$4$1.run(Unknown Source)
  at com.sun.javafx.application.PlatformImpl$4$1.run(Unknown Source)
  at java.security.AccessController.doPrivileged(Native Method)
  at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
  at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
  at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
  at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
  at com.sun.glass.ui.win.WinApplication$3$1.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)

Anyone know what I am missing ?
(I never get to see the form load on the screen and the above error happens as soon as the jar has run)

Java Version installed on PC?
 

Douglas Farias

Expert
Licensed User
Longtime User
@Erel
its possible change the language of the installation? and the java LOGO black image?
 

Douglas Farias

Expert
Licensed User
Longtime User
dont have language options, but i remember the inno setup on my old projects not on b4j.
the setup auto select the language of the pc and make a instalation setup on the language of the pc.

This option are not on this inno version?
know about that?
 

Douglas Farias

Expert
Licensed User
Longtime User
@Erel
i need to compile on diferent pcs the installer?
for example i made the .exe on my pc 64 bits now, and i have sent to my friend with win 32 and the .exe dont run.
show a msg this app cant tun on your pc.

i need to compile on
- 64 Windows
- 32 Windows
- 64 Mac (dont know if this exist, i dont have mac XD)
- 32 Mac (dont know if this exist, i dont have mac XD)
- Any Linux version? i dont know if linux have 32 or 64 too, but id exist i need compile on linux 32 and 64 ?

have a way to make this installer run on all windows versions and 32 & 64?


and the .jar have this rule about 32 and 64?

error image
11949751_874688892616700_711764747_n.jpg
 
Last edited:

Suntzu

Member
Licensed User
Longtime User
I am creating an installer for one of my apps but it is failing. Here is the log:
B4X:
Program started.
C:\Users\XXXX\AppData\Roaming\B4JPackager
App identifier: XXX.XXX.XXXX.main
Success: true
StdOut: Using base JDK at: C:\Program Files\Java\jdk1.8.0_51\jre
Exception: java.io.IOException: Write error
StdErr: Error: Bundler "EXE Installer" (exe) failed to produce a bundle.
ExitCode: -1
C:\Users\XXXX\AppData\Roaming\B4JPackager folder contains these folders and files but without the actual bundled .exe file:

bundles
META-INF
1.exe.html
1.exe.jnlp
XXXX.jar
settings.txt

Any ideas? I'm on jdk1.8.0_60.
 
Last edited:
Status
Not open for further replies.
Top