B4J Tutorial UI apps packaging - self contained installers

Discussion in 'B4J Tutorials' started by Erel, Aug 2, 2015.

  1. Erel

    Erel Administrator Staff Member Licensed User

    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.

    [​IMG]

    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.
    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.
     

    Attached Files:

    Last edited: Sep 6, 2016
    Toley, dar2o3, ilan and 17 others like this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    nrasool and ellpopeb4a like this.
  3. nrasool

    nrasool Member Licensed User

    Nice one Erel, I've used Innosetup in the past and love it, so great project to see them both :)
     
  4. Enrique Gonzalez R

    Enrique Gonzalez R Active 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
     
  5. Enrique Gonzalez R

    Enrique Gonzalez R Active 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...
     
  6. Douglas Farias

    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: Aug 6, 2015
  7. Erel

    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.
     
    Mark Turney likes this.
  8. Enrique Gonzalez R

    Enrique Gonzalez R Active 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)
     
    Erel likes this.
  9. Douglas Farias

    Douglas Farias Expert Licensed User

    Yes you are right, i put down my anti-virus (avast) and dont see any error..


    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?
     
  10. Enrique Gonzalez R

    Enrique Gonzalez R Active Member Licensed User

    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
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Yes. With this installer your app is a regular app. It no longer depends on any other runtime.
     
    Mark Turney and Douglas Farias like this.
  12. Douglas Farias

    Douglas Farias Expert Licensed User

    thx *-* this is very good. i will try now.

    last question, have a way to put a icon on desktop?
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    Add "-BshortcutHint=true" to the arguments.
     
    Douglas Farias likes this.
  14. micro

    micro Well-Known Member Licensed User

    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: Aug 8, 2015
  15. micro

    micro Well-Known Member Licensed User

    Arguments.... Where?
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    Search for the args list.
     
  17. micro

    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
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    No. See the args list in btnBuild_Action sub.
     
  19. micro

    micro Well-Known Member Licensed User

    Ok
    I just downloaded the jar file and not B4jpackager.zip
    Best Regards
     
  20. olivere

    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
     
    ThRuST likes this.
Loading...