JavaFX native App Auto-update feature implementation--fxlauncher

Source: Internet
Author: User
Tags echo message

Read the official demo, or study for a long time to achieve this function. The description is simply too simple.

Reference address: Fxldemo fxlauncher javafx native app auto-update feature implementation--fxlauncher

After reading the reference materials, I still feel the impossible. The information is mainly about the following steps:

Steps to use 1.FXLauncher

1) Compile the project jar to App.dir
2) Copy dependency package to App.dir
3) Generate App.xml Manifest
4) Create a local installer
5) upload artifact to Automatic Update warehouse

No specific steps, can only study the source of Fxldemo and Fxlauncher. After yesterday 12 hours of compilation debugging, finally realized the function. The steps to implement this feature are documented in detail below.


With this feature in perspective, it's better to look back at the official steps. In fact, the most critical part of the step is to generate App.xml manifest.

As long as can deal with App.xml and understand what fxlauncher is a good thing to do.

Here are my specific steps:

2. Open my JavaFX project Mybrowser

(This is the JavaFX to implement the Automatic Update feature.) Refer to Example Fxldemo).


At this point the project should be an app that can be compiled and run, but not automatically updated. Now is the time to implement this function on this basis.

The Mybrowser project was created according to the JavaFX Primer tutorial, Project projects and operations using ant, unlike the Maven used by Fxldemo, so you need to modify the Build.xml according to Pom.xml in Fxldemo.

3. Modify the Build.xml. This is the point.

First post the modified Build.xml file:

<?xml version= "1.0" encoding= "UTF-8"? ><project name= "Addressapp" default= "Create-app-xml" basedir= "." xmlns:fx= "Javafx:com.sun.javafx.tools.ant" ><property name= "Java.jdk.home" value= "H:\Program files\java\ jdk1.8.0_112 "/><property name=" AppName "value=" Mybrowser "/><property name=" Vendor "value=" Mybrowser.pelin "/><property name=" MainClass "value=" application. Main "/><property name=" App.url "value=" http://10.100.1.240:8089/"/><property name=" App.cachedir "value = "Userlib/${appname}"/><property name= "App.dir" value= "${basedir}\dist"/><property name= " App.installerdir "value=" ${basedir}\deploy\bundles "/><!--should the client downgrade if the server version is Olde R than the local version? --><property name= "App.acceptdowngrade" value= "true"/><!--Optional parameters to the application, would be E Mbedded in the launcher and can is overriden on the command line--><property name= "app.parameters" value= "--mYoption=myvalue--myotheroption=myothervalue "/><echo message=" Basedir: ${basedir} "/> <echo message=" App.dir:--cache-dir=${app.cachedir} "/> <echo message=" Java.home:${java.home} "/> <echo message=" Java.jdk.home:${java.jdk.home} "/> <target name=" init-fx-tasks "><path id=" Fxant "><filelist> <file name= "${java.jdk.home}\lib\ant-javafx.jar"/><file name= "${java.jdk.home}\jre\lib\ext\jfxrt.jar"/ ><file name= "${basedir}"/></filelist></path><taskdef resource= "com/sun/javafx/tools/ant/ Antlib.xml "uri=" javafx:com.sun.javafx.tools.ant "classpathref=" fxant "/></target><target name=" Do-compile ' ><delete dir= "build"/><mkdir dir= "Build"/><mkdir dir= "build/classes"/><javac Includeantruntime= "false" source= "1.8" target= "1.8" srcdir= "${basedir}/". /src "destdir=" build/classes "encoding=" GBK "><classpath><fileset dir=" ${basedir}/. /lib "><include name=" **/* "/></fileset></classpath></javac><!--Copy over none java-files--><copy todir= "Build/classes" >< Fileset dir= "${basedir}/. /src "><exclude name=" **/*.java "/></fileset></copy> <!--copy xml-files--><copy todir= "Build/classes" ><fileset dir= "${basedir}/. /config "><filename name=" * * "/></fileset></copy></target><target name=" Do-deploy " Depends= "Do-compile, init-fx-tasks" ><delete dir= "dist"/><delete dir= "deploy"/><mkdir dir= "dist"/ ><copy todir= "Dist" ><fileset dir= "${basedir}\ ..." ><filename name= "* *"/><exclude name= ". settings/**"/><exclude name= "bin/**"/><exclude name= "build/**"/><exclude name= "src**"/><exclude name= ". Classpath"/><exclude name= ". Project"/> <exclude name= "Build.fxbuild"/></fileset></copy><fx:resources id= "AppRes" ><fx:fileset Dir= "Dist" includes= "${appname}.jar"/><fx:fileset dir= "disT "includes=" lib/** "/></fx:resources><!----><fx:resources id=" AppRes2 "><fx:fileset dir=" Dist "includes=" ${appname}.jar "/><fx:fileset dir=" dist "includes=" * * "/></fx:resources> &LT;FX: Application id= "Fxapplication" Name= "${appname}" mainclass= "${mainclass}" version= "1.0"/><!--<mkdir dir= " Build/classes/meta-inf "/>--><fx:jar destfile=" Dist/${appname}.jar "><fx:application refid=" Fxapplication "/><fileset dir=" build/classes "></fileset><fx:resources refid=" AppRes "/>< Manifest><attribute name= "Implementation-vendor" value= "${vendor}"/><attribute name= " Implementation-title "value=" ${appname} "/><attribute name=" implementation-version "value=" 1.0 "/>< Attribute name= "Javafx-feature-proxy" value= "None"/></manifest></fx:jar><echo message= "Start Deployment"/  > <mkdir dir= "Deploy"/><!--need to use ${basedir} because somehow the ant task is calculating the directory DifferentlY <fx:deployembedjnlp= "false" extension= "false" includedt= "false" offlineallowed= "true" outdir= "${basedir}/ Deploy "outfile=" ${appname} "nativebundles=" EXE "updatemode=" background "><fx:platform basedir=" ${ Java.jdk.home} "/><fx:info title=" ${appname} "vendor=" ${vendor} "/><fx:application refid=" fxApplication "/><fx:resources refid=" AppRes2 "/></fx:deploy>--></target><target name=" Create-app-xml "depends=" Do-deploy "><path id=" Lib_classpath "><filelist><file name=" ${basedir}\.        \lib\fxlauncher.jar "/></filelist><fileset dir=" ${java.home} "> <include name=" **/*.jar "/> </fileset> </path><java classname= "Fxlauncher. Createmanifest "classpathref=" Lib_classpath "><arg value=" ${app.url} "/><arg value=" ${mainClass} "/> <arg value= "${app.dir}"/> <arg value= "--cache-dir=${app.cachedir}"/><arg value= "--accept-downgrade= ${app.acceptdowngrade} "/><!--jar file typeis the default, other types are separated by commas. Case insensitive, case mismatch will also load into--><arg value= "--include-extensions=java,dll,properties"/><arg Value= "${app.parameters}"/></java> </target></project>


The main modifications to the place:

①default= "Do-deploy" was changed to default= "Create-app-xml".

② added a new target, <target name= "Create-app-xml" depends= "Do-deploy" >.

③ The relevant parameters that are required by the Create-app-xml task before defining it.

④ Add the Fxlauncher.jar package under the project's Lib directory.

The relevant parameter description:

${app.url}: Is the http://10.100.1.240:8089/in App.xml, this parameter is required

${mainclass}:application. Main, this is the entry class for our JavaFX project. The class where the main method resides when our project is run. This parameter is required

${app.dir}: F:\eclipseworkJavaFX\MyBrowser\build\dist, this is the file directory Fxlauncher to Traverse, Fxlauncher iterates through all the files in that directory and adds the corresponding records in the App.xml (based on the configured--include-extensions=java,dll,properties, so the traversal is only *.java,*.dll,*. The Propertiers type file is added to the App.xml). This parameter is required

${app.cachedir}: Userlib/mybrowser, this is not necessary.

${app.acceptdowngrade}: The example is written in false, what is the specific use has not been studied. This is not necessary.

${app.parameters}:--myoption=myvalue--myotheroption=myothervalue, this is not necessary.

The Fxllauncher.jar tool provides a createmanifest class. This class input related parameters can create app.xml.

Fxlauncher. Createmanifest probably need to know for the time being that's enough.

4. When Ant runs the new task, it generates the App.xml file in the following format.

It's important to understand what App.xml is doing.

<?xml version= "1.0" encoding= "UTF-8" standalone= "yes"? ><application ts= "1491906975319" uri= "/http 10.100.1.240:8089/"launch=" application. Main "> <lib file=" config/config.properties "checksum=" 785530472 "size=" 164 "/> <lib file=" lib/jshortcut-0 _4.jar "checksum=" 109661545 "size=" 85955 "/> <lib file=" Lib/jshortcut.dll "checksum=" 1759411124 "size=" 58368 "/&    Gt <lib file= "Mybrowser.jar" checksum= "3533345451" size= "8774"/> <lib file= "Src/application/main.java" checksum= "972920204" size= "1940"/> <lib file= "Src/application/util/configutil.java" checksum= "1261655196" size= "1071"/> <lib file= "Src/application/util/dialogutil.java" checksum= "3703146705" size= "432"/> <lib F Ile= "Src/application/util/pathutil.java" checksum= "15328486" size= "1965"/> <lib file= "src/application/util/ Shortcututil.java "checksum=" 3757256008 "size=" 3870 "/> <lib file=" src/application/view/ Rootlayoutcontroller.java "checksum=" 3654994656 "size=" 1514 "/> <updateText>Updating...</updateText> <updatelabelstyle>-fx-font-weight: Bold;</updatelabelstyle> <progressBarStyle>-fx-pref-width:200;</progressBarStyle> < wrapperstyle>-fx-spacing:10; -fx-padding:25;</wrapperstyle> <parameters>--myoption=myvalue--myotheroption=myothervalue</ Parameters> <cacheDir>USERLIB/MyBrowser</cacheDir> <acceptdowngrade>true</ Acceptdowngrade> <lingeringUpdateScreen>false</lingeringUpdateScreen></Application>


Application label

TS attribute: This is the time long value generated by the App.xml file. Fxlauncher determine if you need to synchronize the local app.xml remotely. If TS is larger than the local app.xml on the remote server (that is, the Automatic Update warehouse), the remote download app.xml to local. The specific local location is the location in the Cachedir configuration, and mine is H:\Users\Pelin\AppData\Local\MyBrowser\application. Main.xml

URI Properties: Remote server access address.

Launch property: The Mybrowser entry class MainClass that is applied locally.

Lib label

The file property: And the previous URI group composition files, from the address to download files overwritten or added to the local, so that the local app updates. Such as:

Http://10.100.1.240:8089/config/config.properties Http://10.100.1.240:8089/MyBrowser.jar, etc.

So to achieve the local application of Automatic Updates, the above address must be able to download the file properly (this automatic Update warehouse project after deployment)

Checksum and Size properties: The Size property is easy to understand, that is, the file sizes, checksum I did not look closely, but Fxlauncher will be based on these 2 properties to determine whether the local file is up to date, if not it will download the latest from the server. Note: This and the previous TS comparison, synchronization app.xml no relationship, even if the app.xml does not need to update, but these 2 parameters and local files do not match the same will go to the server synchronization update. For example, manually changed the Size property in the App.xml file, causing it to be inconsistent with the local file, Fxlauncher will go to the server each time the boot is synchronized, so you generally do not manually modify the checksum and size properties of the lib tag.

Cachedir Label

<cacheDir>USERLIB/MyBrowser</cacheDir>

The path under this tab represents the location where Fxlauncher downloaded the file from the remote server. Userlib through the fxlauncher resolution, the real directory under Win 7 is:

H:\Users\Pelin\AppData\Local

H means the operating system disk. My operating system is on the H drive, so is H, if the operating system is in the C drive, then the downloaded file should be placed on the C drive.


5. Compress the App.xml file into the Fxlauncher.jar.

It's all done in the front, and it's easier then.

Fxldemo uses the MAVEN plug-in feature and configures the App.xml file to be compressed into the jar. I run the demo to prompt an error, saying that it may be incompatible with my system, always compression is unsuccessful. Mine is the Win7 32-bit system. It is not known why Win7 and Linux systems are the reason for 32-bit and 64-bit systems. Studied for 2 hours, did not take care of, first of all.

Simple and rude workaround: Manually open the jar using WinRAR open mode, and then drag the App.xml file into the jar.

Anyway is the operation once, later release without compression again, is an operation, not so complex.


6. Configure the automatic update of the warehouse server.

This is easy to get, first test pass on the line.

Server ip:10.100.1.240. Then configure Tomcate 8 on the server and change its port number to 8089. If you use the default 8080, the previous configuration corresponds to 8080. The URI in the generated app.xml is also used with 8080.

In short tomcate the port in the boot port and the URI in the app.xml are consistent.


7. The server that will compile the packaged app release.

In my project Build.xml, configure the post-compilation program directory in ${basedir}\dist, which is F:\eclipseworkJavaFX\MyBrowser\build\dist.

Copy all files under this directory to the%tomcate_home%webapps/root directory on the server. (%tomcate_home% indicates tomcate installation directory)


8. Publish your application.

Now you can publish your application, as long as the compressed App.xml Fxlauncher.jar released, the user download Fxlauncher.jar after the run will automatically download the program to Local. The app will start automatically when the download is complete.

Here is the post-boot interface:



9. Publish to the server after the update is applied.


Compile and run the project. Even if you run Build.xml with Ant. Copy all files under the Dist directory to the root directory of tomcate, and the same file will be overwritten.

This will automatically update the local app when the user opens the previous Fxlauncher.jar again. Done!!


This enables the native app auto-Update feature to be implemented. This should be adapted to all jar programs, not necessarily javafx. Fxlauncher just download the update file according to App.xml and start the program according to MainClass.














JavaFX native App Auto-update feature implementation--fxlauncher

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.