Monday, September 15, 2008

Using Java WebStart in NetBeans 6.1

This tutorial assumes that you already have a desktop application project opened in Netbeans, and an Apache web server installed. For a screencast, you can play the movie below:

  1. Right-click on your project’s node in the Projects window.

  2. Select Properties.

  3. Click the Run node, and in the Main Class field, click Browse, and select the class which contains the main() method.

  4. Expand the Application node, and you will see Web Start.

  5. Check the check box for Enable Web Start.

  6. In the Icon field, click on the Browse… button and select the icon image for your application. This should be a 64x64 JPEG or GIF file.

  7. In the Codebase field, select User defined (e.g. HTTP deployment)

  8. In the Codebase Preview field, type the URL where your JNLP file will be stored. In my case, my web server’s IP address is 192.168.1.99, and I want to place my application and the JNLP file in a directory named “webstart” under my web server’s document root. So, I specify http://192.168.1.99/webstart in this field.

  9. If your application does not require a network connection to run, then select the “Allow Offline” check box.

  10. Press OK to close the Project Properties window.

  11. Press F11 to Build the project.

  12. Go to the Files Window by pressing Ctrl+2.

  13. Expand your project’s node, and you should see the dist folder, which should contain the following files:
    YourApp.jar
    • launch.html
    • launch.jnlp
    • your icon file

  14. Locate the dist folder in your file system, and copy its contents to a directory within your web server’s document root. In my case, I place the files in the directory named “webstart”, which is inside my web server’s document root folder. Note that this directory should be the same directory you specified in step 8.

  15. Make sure your web server recognizes the JNLP MIME type. If you are using Apache, you simply need to add the following line to the file named mime.types, which is located in the config folder of your Apache installation.
    application/x-java-jnlp-file JNLP

  16. Start your web server.

  17. In the client machine, make sure the JRE is installed. Access the test page for launching the application via JNLP. In my case, the URL is http://192.168.1.99/webstart/launch.html. Click on the test link and this should launch your application automatically.


Creating Shortcuts for Your Application
If you selected the Allow Offline check box in step 9, you can create Desktop and Start Menu shortcuts for your application. Here’s how.
  1. Go to Control Panel, and double-click on the Java Applet. In the General tab, and under the section for Temporary Internet Files, click on the View… button.

  2. You will see a list of downloaded Web Start applications. Right-click on the application which you want to make shortcuts for, and select Install Shortcuts. Press the Close button.
The shortcuts should now be installed on your desktop and your Start Menu!

No comments: