Question: Which of the following items is not an advantage of self-contained applications?
Answer: C. The application requires more space because the JRE is bundled with the application.
Question: True or False: MIME type must always be used to set up a file association.
Answer: False. Depending on the platform and the bundler used, a MIME type or file extension can be used. For Linux, the MIME type is required. For Windows, the file extension is required. For OS X, either the MIME type or the file extension is required. It is a good practice to provide both the MIME type and file extension when setting up file associations, regardless of the platform.
Question: What elements are used to identify the entry points for self-contained applications in the <fx:deploy>
Ant task?
Answer: The mainClass
attribute of the <fx:application>
element is used to identify the main entry point. If the self-contained application has multiple entry points, the <fx:secondaryLauncher>
element is used for each secondary entry point.
Exercise: Write the <fx:deploy>
Ant task to generate a Windows MSI bundle for a simple application named My Sample App. The JAR file for the application is in the dist
directory, the main class is samples.MyApp
, and output files are to be written to the current directory.
Answer:
<fx:deploy outdir="." outfile="MySampleApp" nativeBundles="msi> <fx:application name="My Sample Application" mainClass="samples.MyApp"/> <fx:resources> <fx:fileset dir="dist" includes="*.jar"/> </fx:resources> <fx:info title="My Sample Application" description="A simple sample app"/> </fx:deploy>
Exercise: Enhance the code in the previous exercise to create bundles for all Windows installers and define a file association for text files.
Answer:
<fx:deploy outdir="." outfile="MySampleApp" nativeBundles="installer"> <fx:application name="My Sample Application" mainClass="samples.MyApp"/> <fx:resources> <fx:fileset dir="dist" includes="*.jar"/> </fx:resources> <fx:info title="My Sample Application" description="A simple sample app"> <fx:association extension="txt" description="Text files"> </fx:association> </fx:info> </fx:deploy>
When the nativeBundles
attribute is set to installer
, the packager attempts to build bundles for all supported installers for that platform. The disk image is not created. If the tools needed to build a particular bundle are not available, that bundle type is skipped.
Windows requires only the extension
attribute when defining file associations.