文档

Java™ 教程-Java Tutorials 中文版
Trail: Deployment
Lesson: Deploying Self-Contained Applications
主页>部署>部署自包含的应用程序

问题和练习的答案:自包含的应用程序

问题

  1. 问题:Which of the following items is not an advantage of self-contained applications?

    1. Users install the application with an installer that is familiar to them.
    2. The application runs as a native application.
    3. The application requires less space on a user's machine.
    4. You control the version of the JRE that is used by the application.
    5. The application does not require a browser to run.

    答案:C. The application requires more space because the JRE is bundled with the application.

  2. 问题:对或错: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.

  3. 问题: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.

练习

  1. 练习: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>
    
  2. 练习: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.


Previous page: Questions and Exercises: Self-Contained Applications