Bookmark and Share

Java Web Start Animation
with NetBeans IDE 6.8

Starting a Project

In this tutorial, we use a simple Java animation with Swing, ColorAnimation.java, which changes color from red to green of a circle.

Select File -> New Project...


Java Web Start: ChooseProject

Keep the standard option which is "Java Application" then click "Next".


Java Web Start: Project Name And Loacation

Type in the project name, "ColorAnimation" and also type in our file name, "ColorAnimation", into the "Create Main Class" text input.
Then click "Finish" button.
Now we see the Project window in the IDE as the picture below.


Java Web Start: Project Window

Time to bring our animation file, using cut and paste, put the "ColorAnimation.jave" into our project.




Configuring the Project to Enable Java Web Start

With Java Web Start, the user can launch a Java application by clicking an HTML link to a JNLP file for this application inside a web browser. The JNLP file, which is a special configuration file, instructs Java Web Start to download, cache, and run the Java application. To run applications with Java Web Start, it is enough to have a compatible version of the Java Runtime Environment (JRE) installed on the client machine. The installation of the Java Development Kit (JDK) is not required.

To enable your Java application to run with Java Web Start, you need to configure the properties of how the IDE should build the project. When Java Web Start is enabled in project properties, the IDE automatically creates a JNLP file and an HTML page with the link to the JNLP file, together with the JAR file.



At first, we configure the project to make it Java Web Start enabled and test its execution locally.

  1. Right-click the "ColorAnimation" project node and choose Properties.
  2. Under Categories, choose Web Start and select the Enable Web Start checkbox.
  3. Leave the Local Execution option selected as the Codebase as we will first run the application locally. The Codebase Preview field shows the path to local application files.

  4. Java Web Start: Project Properties

  5. Ensure that the Self-signed checkbox is selected. The application JAR file will be signed by a certificate that is generated automatically when the project is built. With the self-signed certificate, the application will be able to access the same resources from the computer as a regular application that is running locally. For example, the self-signed certificate allows an application to access local files and the network.
  6. (Optional). In the Project Properties dialog box, select the Applications panel and change the application title and vendor name.

  7. Java Web Start: Project Application Panel




Running the Java Web Start Application from the IDE Locally

To compile and run the application to test Java Web Start locally:

  1. Right-click the "ColorAnimation" project node andand select "Set as Main Project".
  2. Choose Run > Run Main Project or press F6.

  3. Java Web Start:Run Main Project

    The IDE compiles sources and you should see the splash screen that Java is starting and the warning window asking you whether the signed application can be executed.

    Java Web Start:Security Warning

  4. Select the checkbox to trust the content and click Run in the warning window. The "ColorAnimation" application starts.

    Java Web Start:Color AnimationRun



Running the Application from a Remote Location

After you verified that the application starts successfully with Java Web Start from local sources, let's upload it to a remote location and launch it from there.

For deployment of applications with Java Web Start on the web, the web server you are using should be able to handle JNLP files. The web server must be configured to recognize JNLP files as applications, i.e. the MIME type for JNLP should be added to the configuration of the web server. Otherwise, files with the JNLP extension will be treated as usual text files. For more information about web server configuration, refer to the Setting Up JNLP Web Server.

To launch the application from the web, you need to provide a link to the applications source file on the web in the JNLP file.

  1. Right-click the "ColorAnimation" project node, choose Properties and select Web Start under Categories.
  2. Choose User Defined as the Codebase.
  3. In the Codebase Preview field, enter the URL where you will be uploading the source files.

    Java Web Start:Project Properties-Codebase

  4. Click OK in the Project Properties window.
  5. Right-click the "ColorAnimation" node and choose Clean and Build. This IDE command deletes all previously compiled files and build outputs, recompiles your application, and builds output files with current settings.



Uploading the Source Files

Upload the following local files from your project's dist folder to the Downloads area of your project: ColorAnimation.jar, launch.html, and launch.jnlp. The figure below shows the download area for the NetBeans IDE Documentation Area project.

Java Web Start:Uploaded Files on the server



Run Remotely

Now, run your application. In a browser window, enter the URL to the launch.html file. In our case, it is
http://www.bogotobogo.com/Java/ColorAnimation/dist/launch.jnlp
and click the "Launch the application" link.
The "ColorAnimation" application starts with Java Web Start.