转自 http://javafx.com/docs/techtips/deployment_toolkit/
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.js
http://dl.javafx.com/dtfx.js
http://dl.javafx.com/javafx-loading-100x100.gif
http://dl.javafx.com/javafx-loading-25x25.gif
The
deployJava.js
file 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.js
c:/offline/dtfx.js
c:/offline/javafx-loading-100x100.gif
c:/oflline/javafx-loading-25x25.gif
- Edit the
dtfx.js
file to reference the files that you saved to your local computer in step 2:
- Replace the reference to
http://java.com/js/deployJava.js
withfile:/c:/offline/deployJava.js
. - Replace the reference to
http://dl.javafx.com/javafx-loading-100x100.gif
withfile:/c:/offline/javafx-loading-100x100.gif
. - Replace the reference to
http://dl.javafx.com/javafx-loading-25x25.gif
withfile:/c:/offline/javafx-loading-25x25.gif
.
- Replace the reference to
- 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.
On executing this command, you will see the Java splash screen followed by a progress dialog box if any downloading occurs. When the downloading is completed the command will exit silently, indicating that you now have the latest JavaFX runtime cached. If an error is encountered, an error dialog box appears.javaws -import http://dl.javafx.com/javafx-cache.jnlp
- 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"/>
This is the default
The NetBeans IDE regenerates an HTML file and JNLP a file for your JavaFX application and overwrites the changes that you made to the files that you downloaded from<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. <!-- BEGIN SOURCE CODE -->Source Code<?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>
- In your application's HTML page, change the reference of
dtfx.js
to 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
<!-- BEGIN SOURCE CODE -->RippleEffect.html
file after editing to reference the local version of thedtfx.js
script on your computer. Thejavafx()
function is defined indeployjava.js
file 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_height
andloading_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.
<!-- BEGIN JS-KIT RATINGS -->
![]() |
<!-- END JS-KIT RATINGS --><!-- BEGIN LEAVE A COMMENT WIDGET -->
![]() |
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 replies—your information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use.