JavaFX Runtime Redistribution
Last Updated May 2013
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 dl.javafx.com (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:
java-coffee-cup-23x20.png(a default splash screen for applets, used by
javafx-loading-100x100.gif(a default splash screen for applets, used by
javafx-loading-25x25.gif(a default splash screen for applets, used by
javafx-rt-natives-[platform]-[version].jar(an archive of all libraries in the
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-natives.jarin 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.
To set up the JavaFX runtime in the Intranet, follow these steps:
- From the
runtimedirectory, copy everything except the
nativesdirectory to the selected web server directory.
Note: Ensure that you copied resources for all platforms where you deploy your application.
- Open the
javafx-rt.jnlpfile and edit its
codebaseelement so that it points to the current directory where the runtime JNLP and resources are hosted.
- Modify your application or applet so that it points to the correct
dtfs.jsfiles, 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:
- Modify a reference to the
dtfx.jsfile in the index.html page as follows:
- Modify the
<resources>section of the JNLP file to refer to the JavaFX runtime as follows:
Source Code: JNLP File Sample to Reference the JavaFX runtime Stored Locally in Intranet
<resources> <j2se version="1.5+"/> <extension name="JavaFX Runtime" href="http://localhost/javafx/javafx-rt.jnlp"/> <jar href="SpringAnimation.jar" main="true"/> </resources>
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:
- Set the JavaFX runtime JAR file for a target platform (for example,
javafx-rt-windows-i586-1_3_1.jar) and add the
nativesdirectory to the class path.
- Set the JavaFX native libraries to be on a Java library search path or on the system path for shared libraries.
- Set the
Mainclass 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.Mainclass. Assuming that the main class of your application is
yourapp.Main, the parameter should look like
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:
- Include the JavaFX SDK runtime directory (including the
nativesdirectory) in your application bundle.
Note that you must include JAR files for each supported platform. JAR files in the
runtimedirectory contain platform identification in their names, for example,
javafx-rt-natives-windows-i586-1_3_1.jaris intended for the Windows platform. To include JAR files for other platforms, install the appropriate JavaFX SDK and copy the JAR files from the
runtimedirectory. See the Supported Configurations section for the list of supported platforms.
- 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
- Set up the system property (
java.library.path) to include the path to the
- Package your application and start it by invoking
com.sun.javafx.runtime.main.Mainwith the parameter
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.
An offline version of the Java FX runtime supports the following platforms:
- Mac OS X
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.