Book Image

JavaFX 1.2 Application Development Cookbook

By : Vladimir Vivien
Book Image

JavaFX 1.2 Application Development Cookbook

By: Vladimir Vivien

Overview of this book

JavaFX Script enables you to easily create rich Internet applications by embedding multimedia components. Although you can create stylish Internet applications by modifying these default components, even advanced users find it challenging to create impressive feature-rich Internet applications with JavaFX. Also, there are limited JavaFX components to work with and by default these components don't look visually appealing.This book explores limitless possibilities to style your application by coding JavaFX components to display your content in a more appealing fashion. The recipes in this book will help you to create customized JavaFX components with which you can make modern, feature-rich applications.First, you will be introduced to the JavaFX SDK and other development tools available to help you be productive during development. You will create an application in JavaFX by arranging complex graphical components (and non-graphical libraries) with simplified declarative constructs. You will then explore the fun side of JavaFX by using transformation techniques to manipulate the location and dimensions of objects. The next chapter is about the GUI components that are available in the framework, which provide a high level of interactivity. You will learn how to use the media component to play media content. Then we will access data and manipulate data locally or remotely. You will explore many deployment options and integration tips and tricks to take advantage of runtime contexts. Finally, you will interact with pure Java code to read and write files in JavaFX and to establish interactions with computing platforms.
Table of Contents (18 chapters)
JavaFX 1.2 Application Development Cookbook
Credits
About the Author
About the Reviewers
Preface
Mobile JavaFX
JavaFX Composer
JavaFX Products and Frameworks
Best Practices for Development
Best Practices for Deployment

Appendix E. Best Practices for Deployment

The first impression of your application comes from the experience users have as they attempt to procure or launch the application for the first time. It is important to avoid the appearance of a broken application by giving your users the ability to find, download, or start your application easily. Here are some tips for application deployments:

  • Load JARs lazily JavaFX applications jars are downloaded eagerly by default using Java Network Launching Protocol (JNLP). This is fine for smaller applications. However, when you have several large JARs that are part of your application's manifest, this can cause a delay in startup time. You can change this behavior and download JAR files lazily as needed. Update your JNLP file with:

    <jnlp>
    ...
    <resources>
    <jar href="demo-util.jar" download="lazy"/>
    ...
    </resources>
    </jnlp>
    
  • Index your classes one way to improve startup performance is through the use of JAR class indexing. Traditionally, the class loader will traverse each JAR to look for a classes to load. This can be a performance killer at startup to wait for JARs to download and classes to be loaded. Indexing is used to by the class loader to find classes quickly that are embedded in the JARs. To index your classes, use the jar command line tool with the -i option followed by a list of JAR files to be indexed (as shown next). The index information is saved as a text file embedded inside the first JAR file listed in the command.

    jar -i main-app.jar \
    jar-module-1.jar \
    jar-module-2.jar \
    jar-module-3.jar \
    ...
    jar-module-N.jar
    
  • Compress JARs with Pack200 it goes without saying that the size of your JAR files will impact startup time. You can further squeeze the size of your JAR files with the pack200 option when packaging your application with the javafxpacakger, using the -pack200 flag as follows:

    javafxpackager -src src \
    -appClass draggable.demo.Main \
    -appName demo-app \
    -pack200
    
    • In addition to demo-app.jar, this command line also generates the file demo-app.jar.pack.gz that will be downloaded at runtime. The command also injects the property jnlp.packEnabled into the JNLP file as follows:

<jnlp>
...
<resources>
...
<property name="jnlp.packEnabled" value="true"/>
</resources>
</jnlp>
  • Provide ample memory avoid application death caused by 'out of memory' exceptions. This is a nasty situation which can damage the reputation of your app as being broken. The good news is, it can be easily prevented by setting the heap size of your app in the JNLP file

    <jnlp> ...
    <resources>
    <j2se version="1.6+" max-heap-size="256m" />
    ...
    </resources>
    </jnlp>
    
  • Avoid excessive JAR update checks JavaFX applets and Web Start applications will automatically check for updates for the JAR files included in your application upon startup. You can either turn that off (if you don't plan on having updates), or do the update in the background by specifying it in your JNLP file as follows:

    <jnlp>
    ...
    <update check="background"/>
    </jnlp>
    
  • JAR versioning if you decide to have your JARs be updated automatically (see previous bullet point) you can use JNLP's JAR-versioning mechanism. It uses this mechanism to update JAR files when version number changes, instead of checking for updates for all JARs. To take advantage of this, name your JARs using this format {jar-name}_V{version-number}.jar, for example demo-util_V1.0.jar. Then, set the jnlp.versionEnabled attribute in the JNLP file as shown:

    <jnlp>
    ...
    <resources>
    <jar href="demo-app.jar" main="true"/>
    <jar href="demo-util.jar" version="1.0"/>
    <property name="jnlp.versionEnabled" value="true"/>
    <resources>
    </jnlp>
    
  • Avoid signing your application while a properly signed application can establish a certain level of trust, signing, however, can introduce new dialogue boxes that force users to confirm their trust in the application issuer. So, unless you absolutely need signing, avoid it. An unsigned application causes a security dialogue to appear only when the application attempts to execute privileged code. Furthermore, users can opt to trust the the unsigned application and no longer be presented with future security warnings.