Java 教程是为 JDK 8 编写的。本页中描述的示例和实践未利用在后续版本中引入的改进。
问题:Which of the following items is not an advantage of self-contained applications?
答案:C. The application requires more space because the JRE is bundled with the application.
问题:对或错:MIME type must always be used to set up a file association.
答案: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.
问题:What elements are used to identify the entry points for self-contained applications in the <fx:deploy>
Ant task?
答案: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.
练习: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.
答案:
<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>
练习:Enhance the code in the previous exercise to create bundles for all Windows installers and define a file association for text files.
答案:
<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.