How to Develop and Run JavaFX Applications Offline
- Skill Level Beginner
- Product JavaFX
- Key Features JavaFX Deployment
- Last Updated May 2009
This article describes how to use the JavaFX and Java deployment toolkits to modify your JavaFX application to enable execution and
testing when your computer is disconnected from the network.
The deployment toolkit provides JavaScript functions that automatically generate the HTML required to deploy Java Web Start applications.
The deployJava.js file is the Java deployment tookit and the dtfx.js file is the JavaFX deployment tookit.
- You must have the Java SE Development Kit (JDK) 6 Update 10 (minimum).
- Your application must be JNLP enabled.
In the following steps, you download and edit the JavaFX deployment toolkit to enable offline execution of your JavaFX application.
- Download the following files to your computer:
http://java.com/js/deployJava.jshttp://dl.javafx.com/dtfx.jshttp://dl.javafx.com/javafx-loading-100x100.gifhttp://dl.javafx.com/javafx-loading-25x25.gif
The
deployJava.jsfile detects the JRE installation and version, installs the latest JRE version, and enables web pages to run Web Start programs. - Save the files to a local directory on your computer. For Windows create and use
c:\offline. For example:
c:\offline\deployJava.jsc:\offline\dtfx.jsc:\offline\javafx-loading-100x100.gifc:\oflline\javafx-loading-25x25.gif- Edit the
dtfx.jsfile to reference the files that you saved to your local computer in step 2:
- Replace the reference to
http://java.com/js/deployJava.jswithfile:/c:/offline/deployJava.js. - Replace the reference to
http://dl.javafx.com/javafx-loading-100x100.gifwithfile:/c:/offline/javafx-loading-100x100.gif. - Replace the reference to
http://dl.javafx.com/javafx-loading-25x25.gifwithfile:/c:/offline/javafx-loading-25x25.gif. - Execute the following command while your computer is connected to the network. This command ensures that the latest JavaFX runtime is installed in your local cache.
- Disconnect your computer from the network.
- Ensure that the JNLP file for your JavaFX applet or application uses the following
<extension>tag for its JavaFX runtime:
<extension name="JavaFX Runtime" href="http://dl.javafx.com/1.2/javafx-rt.jnlp"/> - In your application's HTML page, change the reference of
dtfx.jsto access your local copy. For example:
Original reference:
<script src="http://dl.javafx.com/1.2/dtfx.js"></script>Reference to access your local copy:
<script src="file:/c:/offline/dtfx.js"></script>This code sample shows the
RippleEffect.htmlfile after editing to reference the local version of thedtfx.jsscript on your computer. Thejavafx()function is defined indeployjava.jsfile of the deployment toolkit. This function deploys your application and is used in the application's HTML file to ensure that you have the correct version of Java software and the JRE software installed. You may also specify a custom splash screen to be displayed while your application is loading.Source Code<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>RippleEffect</title> </head> <body> <h1>RippleEffect</h1> <script src="file:/c:/offline/dtfx.js"></script> <script> javafx( { archive: "RippleEffect.jar", width: 370, height: 450, code: "rippleeffect.Main", name: "RippleEffect" loading_image_url: "http://yourwebsite.com/pictures/companylogo.gif",
loading_image_height: "120",
loading_image_width: "80" } ); </script> </body> </html>You can also include a custom splash screen to be displayed while your application is loading. Type the location of your custom splash screen image by using
loading_image_url. You should specify the dimensions of the image by usingloading_image_heightandloading_image_width. If the dimensions are not specified, the standard 100x100 or 25x25 pixel size will be used.- Run your JavaFX application offline.
For tips on enhancing the performance of your JavaFX application, see the article, How to Improve JavaFx Application Startup Time.


We welcome your participation in our community. Please keep your comments civil and on point. You may optionally provide your email address to be notified of repliesyour information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use.
- Run your JavaFX application offline.
javaws -import http://dl.javafx.com/javafx-cache.jnlp
This is the default <extension> tag that is generated by the NetBeans IDE. This enables your application to be launched offline by using the cached JavaFX runtime.
http://dl.javafx.com. Your changes might also be overwritten when you download an updated version of the deployment toolkit. Therefore, you must make a copy of these offline-specific HTML and JNLP files
and navigate to them directly when running offline. Remember to change the JNLP link in each offline JNLP file that points to the offline copy.
The JNLP file is essential for your application to function on Windows.
The following sample uses code from the the RippleEffect.jnlp file of the RippleEffect JavaFX demo.
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="file:/Users/username/Documents/localdirectory/RippleEffect/dist/" href="RippleEffect.jnlp">
<information>
<title>RippleEffect</title>
<vendor>JavaFX Samples Team</vendor>
<homepage href=""/>
<description>RippleEffect</description>
<offline-allowed/>
<shortcut>
<desktop/>
</shortcut>
</information>
<resources>
<j2se version="1.5+"/>
<extension name="JavaFX Runtime" href="http://dl.javafx.com/1.2/javafx-rt.jnlp"/>
<jar href="RippleEffect.jar" main="true"/>
</resources>
<application-desc main-class="rippleeffect.Main"></application-desc>
</jnlp>
Thomas Ng
Software Engineer, Sun Microsystems