Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Java tip: Deploying JavaFX apps to multiple environments

Get around the 'gotchas' of JavaFX deployment

  • Print
  • Feedback

Page 2 of 3

Deploying JPadFX in a web page and via Java Web Start

You can now use javafxpackager to create an HTML page and a deployment descriptor (JNLP) file to handle the scenarios of embedding the JavaFX application into a web page or running it via Java Web Start. The command in Listing 2 assumes that you are using the same directory used in Listing 1:

Listing 2. Create an HTML page and deployment descriptor for JPadFX via javafxpackager

javafxpackager -deploy -outdir out -outfile JPadFX -width 400 -height
400 -srcdir out -srcfiles jpadfx.jar
               -appclass JPadFX -name "JPad FX" -title "JPadFX Equivalent of
JPad" -vendor "Jeff Friesen" -v

The following options are specified:

  • -deploy tells javafxpackager to create the deployment HTML and JNLP files.
  • -outdir identifies out as the directory in which to store the HTML and JNLP files.
  • -outfile identifies JPadFX as the name of the HTML and JNLP files. This option must be present; otherwise, javafxpackager throws an exception.
  • -width identifies the width of the web page space devoted to the embedded application. I've chosen 400 for the width.
  • -height identifies the height of the web page space devoted to the embedded application. I've chosen 400 for the height.
  • -srcdir identifies out as the directory containing the JAR file.
  • -srcfiles identifies jpadfx.jar as the JAR file.
  • -appclass identifies JPadFX as the main application class to be executed.
  • -name identifies JPad FX as the name of the application. This information appears as the heading on the HTML page. If the name has a space, enclose the string in quotation marks.
  • -title identifies JPadFX Equivalent of JPad as the application's title. This information is stored in the JNLP file.
  • -vendor identifies Jeff Friesen as the application's vendor. This information is stored in the JNLP file.
  • -v specifies verbose output, which can be useful should an error message be displayed.

At this point, your out directory should contain JPadFX.jnlp and JPadFX.html along with jpadfx.jar.

Because JPadFX accesses the local filesystem, you must sign jpadfx.jar; otherwise, an exception will be thrown when you try to perform a file-oriented task, when the application is embedded in a web page or run from Java Web Start. Assuming that you haven't purchased a certificate, you also need to create a self-signed certificate. Use the JDK's keytool program to perform both tasks, as follows:

keytool -genkey -keystore jpadfx.ks -alias jpadfx
keytool -selfcert -alias jpadfx -keystore jpadfx.ks

This command creates a new key in a new keystore named jpadfx.ks, which is created in the current directory. For convenience, I've specified jpadfx as the alias. You will be prompted for information regarding the new key, such as password, name, and so on. Simply follow the prompts.

The second command creates a self-signed test certificate. You'll be prompted to enter a password and then the certificate will be created.

Unfortunately, it is problematic to use javafxpackager to sign the previously created jpadfx.jar file with the test certificate. For this reason, I use the jarsigner command directly, as demonstrated below:

  • Print
  • Feedback

Resources

More from JavaWorld

  • Find more of Jeff's writing in Java Tutor, his blog on JavaWorld.
  • See the JavaWorld Site Map for a complete listing of research centers focused on client-side, enterprise, and core Java development tools and topics.