B4J Tutorial UI apps packaging - self contained installers

Status
Not open for further replies.

Erel

Administrator
Staff member
Licensed User
It is recommended to use B4JPackager11: https://www.b4x.com/android/forum/threads/b4jpackager11-the-simplest-way-to-distribute-ui-apps.99835/

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.



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/threads/using-b4jpackager-bundler-dmg-installer-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

Last edited:

nrasool

Member
Licensed User
Nice one Erel, I've used Innosetup in the past and love it, so great project to see them both :)
 

Enrique Gonzalez R

Well-Known Member
Licensed User
sorry

i gon an error, it seems that it will run only with JDK 8U52?? i have 8U45 i am updating it at the moment, but the java page shows only to 8U51???

Program started.
App identifier: b4j.example.main
Success: true
StdOut:
StdErr: java.lang.UnsupportedClassVersionError: com/sun/javafx/tools/packager/Main : 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 sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Exception in thread "main"
ExitCode: 1
 

Enrique Gonzalez R

Well-Known Member
Licensed User
Okey i solved it, my enviroment variable was pointed to JRE 1.7.XXXX, changed to JRE 1.8.XXXX and worked like a charm.

Unsupported major.minor version 52.0 <--- this has nothing to do with the Java JDK version, it is a kind of error code. silly me...
 

Douglas Farias

Expert
Licensed User
@Erel , using this installer will auto instal the java on pcs without java?
i have a big problem, some peoples dont know download java or dont want install, this tool make this? install java and the app too?

I made a test with on my pc (only to report)
Windows: www.b4x.com/b4j/files/GoogleMapsExample.exe

1- show a error when i execute the installer
error.jpg



2 - later i press ok, show me the instalation, i press continue etc etc... later done show this error. (99%)
error2.jpg


later i press a button to close this error, and the google maps app start normal.

i have tested some times and have the same errors, it is your example any changes, only downloaded and installed.
 
Last edited:

Erel

Administrator
Staff member
Licensed User
It doesn't install Java on the computer. It embeds the JRE in your app files (you can see it under Program Files). So the user doesn't need to do anything with java.

I did test it on Windows XP, Windows 7, Windows 8 and Windows 10. It worked on all computers.

Try to check Event Viewer to see if there is more information about this error.
 

Enrique Gonzalez R

Well-Known Member
Licensed User
i find two possible solutions:

that usually happens when you try install software with embeded runtime and the Antivirus. shutdown the antivirus for some secs, the antivirus blocks the main components from replication themselves in the OS.

the other is running with administrator privilages, some apps do not trigger the request (in my case, the android sdk downloader always init without it)
 

Douglas Farias

Expert
Licensed User
i find two possible solutions:

that usually happens when you try install software with embeded runtime and the Antivirus. shutdown the antivirus for some secs, the antivirus blocks the main components from replication themselves in the OS.

the other is running with administrator privilages, some apps do not trigger the request (in my case, the android sdk downloader always init without it)
Yes you are right, i put down my anti-virus (avast) and dont see any error..


It doesn't install Java on the computer. It embeds the JRE in your app files (you can see it under Program Files). So the user doesn't need to do anything with java.
Hard to understand english here :(, if the user download and install with this installer will automatic install on pc the JRE, and this will run my app?
For example only with this installer the user dont need download anything to run the app?
 

Enrique Gonzalez R

Well-Known Member
Licensed User
Hard to understand english here :(, if the user download and install with this installer will automatic install on pc the JRE, and this will run my app?
For example only with this installer the user dont need download anything to run the app?
That is correct, JRE is more than enough to run your app.

on the other hand, for what i understand, it runs only for your app, if any other app wants to be installed, it will require JAVA, or to be embeded with the JRE too
 

micro

Well-Known Member
Licensed User
Dim os As String = GetSystemProperty("os.name", "").ToLowerCase
If os.Contains("win") Then
workingFolder = File.Combine(GetEnvironmentVariable("AppData", ""), "YourAppName")
File.MakeDir(workingFolder, "")
Else
workingFolder = File.DirApp
End If
Hi Erel
but this code is to be incorporated in the code program?
And workingFolder is to be used in the program instead of File.DirApp?
Thanks

...Ok, work.
 
Last edited:

micro

Well-Known Member
Licensed User
I'm sorry Herel
but I do not understand.
Args () in Appstart? (I do not believe)
I think must be an option for installation.
I used the search but not found what I needed to know
 

olivere

Member
Licensed User
Hi Erel,

I just try to follow this tutorial, but it does not work here:

I run B4JPackager.jar and set the parameter (using jdk1.8.0_51); I receive the message "Package built successfully".

The folders %appdata%\B4JPackager and %appdata%\B4JPackager\META-INF are created and contain data, but
a) there is no folder \output
b) there is no exe

I then manually create a folder %appdata%\B4JPackager\output; after "Package built successfully" this folder is shown as should - but this folder is empty.


Do you have any ideas ? Using Win7/64bit

Thank you and best regards
Oliver

PS: DL of archiver lib ist not accessible
 
Status
Not open for further replies.
Top