Deploying JavaFX Applications

Previous
Next

JavaFX Ant Task Reference

The following items comprise the main JavaFX Ant tasks:

Items are in alphabetical order.


<fx:csstobin>

Description

Converts a set of CSS files into binary form (BSS).

Parent Elements

None.

Parameters

Table 12-1 Attributes of the <fx:csstobin> Element

Attribute Description Type Required?

outdir

Name of the directory in which output files are generated.

String

Yes


Parameters Accepted as Nested Elements

<fx:csstobin> Task Usage Examples

Example 1   Convert CSS Files to Binary

This example converts all CSS files in the output tree to binary form.

<fx:csstobin outdir="build/classes">
    <fileset dir="build/classes" includes="**/*.css"/>
</fx:csstobin>

<fx:deploy>

Description

Generates a package for both web deployment and standalone applications. The package includes a set of JAR files, a JNLP file, and an HTML file.

Parent Elements

None.

Parameters

Table 12-2 Attributes of the <fx:deploy> Element

Attribute Description Type Required?

embeddedHeight

If present, this value will be used for Javascript/HMTL code instead of width/height. Affects only embedded deployment mode.

Use it if you want to specify a relative dimension for an embedded application.

See Section 5.8.4, "Publishing an Application that Fills the Browser Window."

String

No

embeddedWidth

Same description as for embeddedHeight.

String

No

embedjnlp

If true, embed the JNLP descriptor into the web page. Reduces number of network connections to be made on startup and helps to improve startup time.

Boolean

No

Default is false.

extension

Treat the files named in srcfiles as extensions. If present, only a portion of the deployment descriptor is generated, and the HTML file is not generated.

Boolean

No

Default is false.

height

Height of the application scene, for embedding applications into a web page.

String

Yes

includeDT

If set to true, files related to the Deployment Toolkit will be copied to a web-files subdirectory of the directory specified in outdir. This setting is useful for offline development but is not advised for production.

Boolean

No

Default is false.

nativeBundles

Values:

  • all

  • deb

  • dmg

  • exe

  • image

  • msi

  • none

  • rpm

Value all produces all applicable self-contained application packages. Value none produces no self-contained application packages. Or use another value to produce a specific package installer.

String

No

Default is none.

offlineAllowed

If the value is true, the cached application can operate even if the client system is disconnected from the network.

Boolean

Default is true.

outdir

Name of the directory in which output files are generated.

String

Yes

outfile

Prefix of the output files, without the extension.

String

Yes

placeholderref

Placeholder in the web page where the application will be embedded. This is expected to be JavaScript DOM object.

String

Yes

Either reference or ID of placeholder is required.

placeholderid

Used with callbacks. The ID of the placeholder in the web page where application will be embedded. The JavaScript function document.getElementById() is used to resolve it.

String

Yes

Either the reference or the ID of the placeholder is required.

updatemode

Indicates the preferences for when checks for application updates are performed for embedded and Web Start applications.

A value of always means to always check for updates before launching the application.

A value of background means to launch the application while checking for updates in the background.

See Section 5.9.1, "Background Update Check for the Application."

String

No

Default is background.

width

Width of the application scene, for embedding applications into a web page.

String

Yes


Parameters Accepted as Nested Elements

<fx:deploy> Task Usage Examples

Example 1   Minimal <fx:deploy> Task

This is a simple example of an <fx:deploy> Ant task. It generates an HTML file and JNLP file into the web-dist directory and uses "Fish" as the prefix for the generated files.

<fx:deploy width="600" height="400"
        outdir="web-dist" outfile="Fish" 
        offlineAllowed="false">
    <fx:info title="Sample application"/>
    <fx:application refid="myapp"/>
    <fx:resources refid="myresources"/>
</fx:deploy>  
Example 2   <fx:deploy> Task for an Application with a Preloader

The following Ant task creates a redistributable package for a simple application with a preloader. Details about the application and its resources are defined in the <fx:application> and <resource> elements in the task.

Note that the location of the output package is defined by the outdir attribute of the <fx:deploy> task. New files are generated using the name prefix specified in the outfile attribute. As a result of execution of this task, the following files are created in the web-dist folder:

  • preloader.jar

  • helloworld.jar

  • App.jnlp

  • App.html


Note:

By default, the deployment package uses auxiliary files from java.com to support web deployment. This is the preferred way, because it enables the application to always use the best way to deploy on the web. However, if you want to test your application in a closed network then you can include these files into your application package. To do this, pass includeDT="true" as an attribute in the <fx:deploy> Ant task.


<fx:deploy width="600" height="400"
        outdir="web-dist" outfile="App">
    <fx:info title="Sample application"/>
    <fx:application name="SampleApp" 
            mainClass="testapp.MainApp"
            preloaderClass="testpreloader.Preloader">
        <fx:param name="testVariable" value="10"/>
    </fx:application>
    <fx:resources>
        <fx:fileset requiredFor="preloader" dir="dist">
            <include name="preloader.jar"/>
        </fx:fileset>
        <fx:fileset dir="dist">
            <include name="helloworld.jar"/>
        </fx:fileset>
    </fx:resources>
</fx:deploy>

<fx:jar>

Description

Packages a JavaFX application into a JAR file. The set of files to be included is defined by nested <fx:fileset> parameters. The <fx:jar> task also embeds a JAR manifest into the JAR file.

In addition to creating a JAR archive, this task also:

  • Embeds the JavaFX launcher, which detects the presence of JavaFX Runtime, sets up the environment, and executes the application.

  • Embeds the fallback AWT applet, to be used if JavaFX is not available.

  • Creates a manifest in the JAR file.

The resulting JAR file supports launching by double-clicking.

Parent Elements

None.

Parameters

Table 12-3 Attributes of the <fx:jar> Element

Attribute Description Type Required?

destfile

Path to output JAR file (location and name)

String

Yes


Parameters Accepted as Nested Elements

<fx:jar> Usage Examples

See Example 12-2 and the following example.

Example 1   <fx:jar> Ant Task for a Simple Application

This example shows how to use the <fx:jar> Ant task to create the main application JAR file for a simple application without a custom preloader. The resulting JAR file performs the following two actions:

  • Starts test.MyApplication with all resources needed on the classpath when launched as java -jar application.jar or by double-clicking the JAR file.

  • Automatically detects the location of JavaFX Runtime and prompts the user to install it if it is not available, or reports if the platform is not supported.

<!-- Expect definition of JavaFX ant tasks is already imported -->
 
<fx:jar destfile="dist/application.jar">
    <!-- Details about application -->
    <fx:application name="Sample JavaFX application"
            mainClass="test.MyApplication"/>
 
    <!-- Define what auxilary resources are needed -->
    <fx:resources>
        <fx:fileset dir="dist" includes="lib/*.jar"/>
    </fx:resources>
            
    <!-- What to include into result jar file?
         Everything in the build tree -->
    <fileset dir="build/classes"/>
 
    <!-- Customize jar manifest (optional) -->
    <manifest>
        <attribute name="Implementation-Vendor" value="Samples Team"/>
        <attribute name="Implementation-Version" value="1.0"/>
    </manifest>
</fx:jar>   

<fx:signjar>

Description

Digitally signs an application JAR file with a certificate.

Signs the JAR file as BLOB. In other words, instead of every entry being signed separately, the JAR file is signed as a single binary object.

This is a new signing method in JavaFX. For traditional signing, the standard Ant signjar task should be used.

Parent Elements

None.

Parameters

Table 12-4 Attributes of the <fx:signjar> Element

Attribute Description Type Required?

alias

The alias for the key

String

Yes

destdir

Location of output file

String

Yes

keypass

Password for the private key

String

Yes

keystore

Keystore file name

File

Yes

jar

The JAR file to sign*

String

No

Either this attribute or a nested <fx:fileset> element is required.

storepass

Password to check integrity of the keystore or unlock the keystore

String

Yes

storetype

Keystore type

String

No

Default is jks.

verbose

Enable verbose output.

Boolean

No

Default is false.


*Note that:

<fx:signjar jar="path/to/jar/folder/jarname" .../>

is simply a convenience syntax for the following:

<fx:signjar ...>
    <fileset dir="path/to/jar/folder" file="jarname"/> 
</fx:signjar>

Parameters Accepted as Nested Elements

<fx:signjar> Usage Examples

Example 1   Sign JAR Files

The following snippet of Ant code shows how to sign JAR files using the new sign as BLOB technique.

<fx:signjar destdir="dist"
        keyStore="sampleKeystore.jks" storePass="****"
        alias="javafx" keyPass="****">
    <fileset dir='dist/*.jar'/>
</fx:signjar>
Previous
Next