JavaFX Runtime Redistribution

This article features a redistribution of the JavaFX desktop runtime available since the JavaFX 1.3.1 version.


Prior to JavaFX 1.3.1, there were two ways to execute JavaFX desktop applications:

  • By using the JavaFX runtime that is automatically installed from the (for applets and Web Start applications)
  • By installing JavaFX SDK and running standalone JavaFX applications (JavaFX desktop runtime is a part of the SDK)

JavaFX 1.3.1 introduces the ability to redistribute the JavaFX desktop runtime with a JavaFX application, host the runtime on a web server, or redistribute it in some other way. This enables many scenarios that require deploying the JavaFX desktop runtime locally, such as:

  • JavaFX applications are hosted on the intranet where users do not have access to Internet.
  • A JavaFX application is a component of another application that has its own native launcher.
  • A JavaFX applet or Web Start application must be developed or tested without connection to the Internet.

The following sections explain how to redistribute the JavaFX desktop runtime with your application.

JavaFX 1.3.1 SDK Runtime Directory

The redistributable JavaFX desktop runtime is part of the JavaFX SDK since version 1.3.1. The SDK includes the runtime directory that contains a platform specific version of the JavaFX desktop runtime for redistribution. If you want to deploy your application on several platforms, then you must include runtime directories from all platforms in your distribution package.

The runtime directory contains the following files:

  • dtfx.js (JavaScript entry point for browser applets)
  • java-coffee-cup-23x20.png (a default splash screen for applets, used by dtfx.js)
  • javafx-loading-100x100.gif (a default splash screen for applets, used by dtfx.js)
  • javafx-loading-25x25.gif (a default splash screen for applets, used by dtfx.js)
  • javafx-rt-natives-[platform]-[version].jar (an archive of all libraries in the natives directory)
  • javafx-rt-[platform]-[version].jar (an archive of all JavaFX desktop runtime classes for the current platform)
  • javafx-rt.jnlp (Java FX runtime JNLP file - codebase will be where the runtime directory is installed locally; points to javafx-rt.jar and javafx-rt-natives.jar in the same directory); contains the list of resources for all supported platforms
  • jmc-natives-windows-i586-1_3_1.jar (Windows-only native JAR file for Java Media Components)
  • natives (a directory that contains all required native libraries for the current platform)
  • progressbar-1_3_1.jar (a default progress bar for Java FX runtime)
  • splash.gif (a default splash screen for Web Start applications)

The next sections provide step-by-step instructions on how to use the files from the desktop directory to redistribute the JavaFX desktop runtime with applications.

JavaFX Desktop Runtime Redistribution in the Intranet

To set up the JavaFX runtime in the Intranet, follow these steps:

  1. From the runtime directory, copy everything except the natives directory to the selected web server directory.
    Note: Ensure that you copied resources for all platforms where you deploy your application.
  2. Open the javafx-rt.jnlp file and edit its codebase element so that it points to the current directory where the runtime JNLP and resources are hosted.
  3. Modify your application or applet so that it points to the correct javafx-rt.jnlp and dtfs.js files, and modify the JNLP and HTML files.

Assuming that the directory where you store a copy of the JavaFX desktop runtime for redistribution is accessible at http://localhost/javafx, use this runtime with the Spring Animation sample from the SDK, by following these steps:

  1. Modify a reference to the dtfx.js file in the index.html page as follows:

  2. Source Code: HTML Code Sample to Reference dtfx.js Stored Locally in Intranet
    <script src="http://localhost/javafx/dtfx.js"></script>

  3. Modify the <resources> section of the JNLP file to refer to the JavaFX runtime as follows:

  4. Source Code: JNLP File Sample to Reference the JavaFX runtime Stored Locally in Intranet
    <j2se version="1.5+"/>
       <extension name="JavaFX Runtime" href="http://localhost/javafx/javafx-rt.jnlp"/>
       <jar href="SpringAnimation.jar" main="true"/>

To update the JavaFX runtime on the Intranet, create the new version of the JavaFX runtime JAR and JNLP files, as well as the dtfx.js file and modify the application JNLP file and HTML page to point to the updated version.

The JARs for the JavaFX runtime listed in javafx-rt.jnlp provided in the SDK are not signed. For re-distribution via JNLP developers need to sign all the JARs listed in the javafx-rt.jnlp with their own certificate for the deployment to work.

Bundling JavaFX Runtime with a Standalone Application

To execute a JavaFX application, set the following in the JVM:

  1. Set the JavaFX runtime JAR file for a target platform (for example, javafx-rt-windows-i586-1_3_1.jar) and add the natives directory to the class path.
  2. Set the JavaFX native libraries to be on a Java library search path or on the system path for shared libraries.
  3. Set the Main class of your application so that it is not invoked directly. Instead, it should be passed as a parameter to the com.sun.javafx.runtime.main.Main class. Assuming that the main class of your application is yourapp.Main, the parameter should look like MainJavaFXScript=yourapp.Main.

For example, if you want to use the java.exe file to run your JavaFX application and your copy of the JavaFX runtime is stored in the c:\fxruntime directory, then use the following command to start your application:

java -cp "c:\Program Files\JavaFX\javafx-sdk1.3\runtime\javafx-rt-windows-i586-1_3_1.jar";MediaBox.jar -Djava.library.path="c:\Program Files\JavaFX\javafx-sdk1.3\runtime\natives" com.sun.javafx.runtime.main.Main MainJavaFXScript=com.sun.javafx.mediabox.Main

Note that the same steps are applicable if you want to use any other launcher including your own native launcher.

If you want to run a standalone JavaFX application without the SDK, you can provide a custom native launcher instead of calling java.exe. To do this, follow these steps:

  1. Include the JavaFX SDK runtime directory (including the natives directory) in your application bundle.
    Note that you must include JAR files for each supported platform. JAR files in the runtime directory contain platform identification in their names, for example, javafx-rt-natives-windows-i586-1_3_1.jar is intended for the Windows platform. To include JAR files for other platforms, install the appropriate JavaFX SDK and copy the JAR files from the runtime directory. See the Supported Configurations section for the list of supported platforms.
  2. Set up application class path to include the JAR files from the runtime directory:
    java -cp javafx-rt-natives-windows-i586-1_3_1.jar
  3. Set up the system property (java.library.path) to include the path to the natives directory:
    java -Djava.library.path=c:\javafx-natives
  4. Package your application and start it by invoking
    com.sun.javafx.runtime.main.Main with the parameter MainJavaFXScript=yourapp.Main

For example, you can use a program written in C language, create a JVM in it and pass the parameters.

To update the distributable runtime to a newer version, perform one of the following:

  • If you host your runtime on the intranet, update the Java FX runtime URLs in the JNLP file to point to a new runtime version.
  • If you use your own custom launcher, bundle a new application version with a new version of the JavaFX runtime.

Supported Configurations

An offline version of the Java FX runtime supports the following platforms:

  • Windows
  • Mac OS X
  • Linux

Note that the redistributable version of the JavaFX desktop runtime does not provide media support on Linux due to license restrictions. If you use the offline JavaFX desktop runtime with a video player sample on Linux, you will be notified that the media cannot be played, however, other parts of your application will still function.

Download the JavaFX 1.3.1 SDK from the Java Archives