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:

olivere

Member
Licensed User
Longtime User
I forgot: you mention the need of InnoSetup on Windows PC.
Why is this needed ? If B4J Packager creates a single installer exe, there should be no need for InnoSetup ?
 

olivere

Member
Licensed User
Longtime User
No, there must be another reason: InnoSetup is installed (Build 5.5.6), also the Inno SetupStudio..
Doy ou have another idea ?
 

Douglas Farias

Expert
Licensed User
Longtime User
@Erel
1 - Question About Folder
you sample code
B4X:
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
its only for write comand?
for example i have this code on my app.
B4X:
File.Copy(File.DirAssets, "Update.jar", File.DirApp, "Update.jar")
i need to use your code on this case?


2 - Run Adminitrator
I have tested the installer on my another pc with windows 10, the installer works fine, later create a icon o start menu.
But when i click app open and close fast, open show for 1s and close.
To fix this i need to run as administrator, when i run a administrator works fine.

Have a way to ever run a administrator? or ever show a option to run with administrator?
if dont run with administrator my app dont work.


3 - Change Unknown Folder on start menu
un.png


how can i chance this folder name?
 

olivere

Member
Licensed User
Longtime User
No, there must be another reason: InnoSetup is installed (Build 5.5.6), also the Inno SetupStudio..
Doy ou have another idea ?
I found the solution (maybe also of interest for others): add installation path of InnoSetup to PATH variable in your windows environment variables.
 

olivere

Member
Licensed User
Longtime User
Sorry to bother you again: there seeem to be another issue.
I installed your GoogleMapsExample.exe - on my Windows7 (64) all works perfectly. Then I tried with Windows XP and Windows 8 (each "naked" as out of the box) in virtual machines: installations performs without error, but when running an error occurs: no valid 32bit application.

Is it possible, that you've created the package on a 64bit system, such the exe is 64bit too ? If yes, is there a way to choose the type, that you can package also a 32bit deployment on a 64bit system ?

Thank you and best regards
Oliver
 

Attachments

  • Zwischenablage03.jpg
    Zwischenablage03.jpg
    245.3 KB · Views: 460

Erel

B4X founder
Staff member
Licensed User
Longtime User
@Douglas Farias
1. https://www.b4x.com/android/forum/threads/data-folder.56874/
2. I'm not sure why you need administrator access. I tried it on Windows 10 and it didn't ask for administrator access (and worked properly).
3. See the win.menuGroup parameter: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javapackager.html#BGBIJBHF

@olivere
Please try to create a new installer and use a 32 bit version of Java JDK. Set it under Tools - Configure Paths. It should point to Program Files (x86).
Such an installer will work on both 32 bit and 64 bit.
 

tdocs2

Well-Known Member
Licensed User
Longtime User
@Erel and @Douglas Farias

Thank you, Erel - this is really good... :):):)

I muddled my way to get it to work... @Douglas Farias - I did not need admin in Win 10.

1. It installs the app as an .exe in Program Files\yourfolder which I assume it is the Name used in the Packager.

However, one question (same as Douglass):

1. The shortcut to the app is put in folder Unknown. How is that changed? I could not follow the discussion win.menuGroup=group parameter.

win.menuGroup=group
Menu group in which to install the application when menuHint is true. This argument is ignored when menuHint is false.

Thank you.

Sandy

PS: EDIT: I was successful in running the Myapp.exe in Win 7 with no JAVA installed. I had failed to copy one DB to the Win 7 PC. Mea culpa.
 
Last edited:

Roycefer

Well-Known Member
Licensed User
Longtime User
Run Myapp.exe from the command line to see what errors or exceptions are reported.

Make sure Myapp.jar works outside the IDE on a computer that has Java installed.

Make sure Myapp.exe isn't trying to write to File.DirApp.
 

Douglas Farias

Expert
Licensed User
Longtime User
PS: I installed successfully on a Win 7 PC that does not have JAVA. Myapp.exe fails to execute even when I run directly from Program Files... Help please.
Rebooted Win 7, tried running as Admin to no avail; Check compatibility - just said Incompatible Application.

this is the problem i have reported, same error, try with run administrator. (i have tested on win 10 without java too)
later i run administrator first time dont have error anymore
 

tdocs2

Well-Known Member
Licensed User
Longtime User
@Roycefer @Douglas Farias

I was successful in running the Myapp.exe in Win 7 with no JAVA installed. I had failed to copy one DB to the Win 7 PC.

Thank you, Roycefer :). Your diagnostic suggestions made me put my thinking cap on.

Douglass, Do you have all the files your app needs?

Sandy
 

Douglas Farias

Expert
Licensed User
Longtime User
Yes, i dont have the error more, only first time but no problem :)
 

micro

Well-Known Member
Licensed User
Longtime User
Hi,
the installation package created is executed correctly, but when I click on the icon, says that the version is not compatible with the version of installed window.
Package and program code developed on win7/8 64 bit and package installed on win7 32bit.
How I can fix it?
Thanks
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Thank you, Erel.

Try this from the menu name. Add the following line after the args.AddAll line:
B4X:
args.AddAll(Array("-BmenuHint=true", "-Bwin.menuGroup=Test"))

The menu group continues to be Unknown. This is the code - I tried it after the Addall and within the Addall in the Sub btnBuild_Action.
I did not understand what you meant "from the menu name" - I assumed "for the menu group name"

B4X:
        args.AddAll(Array ("-deploy", "-srcFiles", txtJar.Text, "-native", packageExtension, _
            "-BsystemWide=true", "-title", txtTitle.Text, "-name", txtName.Text, "-outdir", workingFolder, _
            "-outfile", "1.exe", "-BshortcutHint=true", "-BmenuHint=true", "-Bwin.menuGroup=Test", "-BappVersion=" & txtVersion.Text, "-appclass", appClass, _
            "-Bidentifier=" & appClass))
'        args.AddAll(Array("-BmenuHint=true", "-Bwin.menuGroup=Test"))

Sandy
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Micro,
Try this:
Download and install a 32-bit JDK on your development computer. On Oracle's website, it will be named the same except for having "-x64" at the end replaced with "-i586".
Follow all the steps enumerated by Erel in the original post, except replace all the Java addresses with the equivalents in your 32-bit JDK. They will probably be under "Program Files(x86)".
This should build a 32-bit executable with an embedded 32-bit JRE.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I did not understand what you meant "from the menu name" - I assumed "for the menu group name"
I also do not understand what I meant :)

Please try to replace the app package name and then use this tool to build a new installer. Maybe Windows remembers the previously installed menu group.
 

tdocs2

Well-Known Member
Licensed User
Longtime User
Please try to replace the app package name and then use this tool to build a new installer. Maybe Windows remembers the previously installed menu group.

As usual, you are correct - it was a Windows latency issue. I changed the app package name and it worked - the appropriate menu group was created. SOLVED.

Can't give deserved double likes - :):)

Best regards.

Sandy
 

micro

Well-Known Member
Licensed User
Longtime User
Micro,
Try this:
Download and install a 32-bit JDK on your development computer. On Oracle's website, it will be named the same except for having "-x64" at the end replaced with "-i586".
Follow all the steps enumerated by Erel in the original post, except replace all the Java addresses with the equivalents in your 32-bit JDK. They will probably be under "Program Files(x86)".
This should build a 32-bit executable with an embedded 32-bit JRE.

Installed 32-bit JDK and when run build in a few second (too few) appears a window message "Package built successfully" but the folder is empty.
Why?
 
Status
Not open for further replies.
Top