Building a web-startable NetBeans RCP application

The NetBeans RCP is a great tool for building the rich client desktop applications. But there is one even more stunning feature hidden – you can build the JNLP (web-startable) applications built on the NetBeans platform.

In plain English: You can make a package with your NetBeans RCP application. If you place this package on the web, users can launch your application without installation, by simply clicking a link on the web page. This way, you can (for example) distribute an application in your company without requiring employees to install it or perform updates.

Building of JNLP Application is simple in general – we will describe the process anyway. But may you come across this issue with missing jnlp-servlet.jar:

# The following error occurred while executing this line:
# Point -Djnlp.servlet.jar to your jnlp-servlet.jar, usually in 
# $JDKHOME/sample/jnlp/servlet/jnlp-servlet.jar

The fix is simple – you just need to get the JAR file and make sure the IDE can see it.

Create a NetBeans RCP application

We will start by creating a vanilla NetBeans RCP application. After you launch your NetBeans IDE 6.9.1, create a new NetBeans Application project:

  1. Invoke File > New Project
  2. Select NetBeans Modules > NetBeans Platform Application and click Next
  3. Fill in some project name and click Finish (you can fiddle the platform and paths, but it is not relevant to this tutorial)

At this stage, a Netbeans Application (a special suite of NetBeans modules) is created – you should see it in the Projects view with two sub-nodes: Modules and Important Files.

Modify project configuration

Modify NetBeans Platform properties, so that you point to the official JNLP and modules location:

  1. Expand the Important Files node in the Projects view
  2. Open the NetBeans Platform Config file (platform.properties) and add following line (replace version if needed)
    jnlp.platform.codebase=http://bits.netbeans.org/6.9.1/jnlp/
  3. Right-click the module suite and invoke Build JNLP Application

After the build process successfully finished, open the Files view in the NetBeans IDE and locate the dist folder under the application folder. There is a WAR file that you can use with your favorite Java server, for example Glassfish.

All you need to do in order to let your users launch the application is to link the master.jnlp file (for example, add an index.html page to the WAR with this link in it):

<a href="master.jnlp">Magic Button</a>

Missing jnlp-servlet.jar file

This problem occurs on MacOS X, but I also met it on fresh Ubuntu 10.04: there is no jnlp-servlet.jar in the JDK distribution. In order to resolve this problem, you need to:

  1. Get the jnlp-servlet.jar at the Java Webstart Download page
  2. Make sure NetBeans IDE can see the JAR when building your application. There are two ways to accomplish this:
    • Either copy the JAR to the JDK folder (you need to be the admin) – this is the suggested way, since you will not break the functionality to your collaborators on different platforms:
      cd /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/
      sudo mkdir sample
      sudo mkdir jnlp
      sudo mkdir servlet
      sudo cp ~/jnlp-servlet.jar /sample/jnlp/servlet/
    • Or, tell the NetBeans IDE where to find the JAR by adding a line to the project.properties file (it is under Important Files, as Project Properties):
      jnlp.servlet.jar=/Users/$USERNAME/jnlp-servlet.jar

Now, the build should pass correctly.

Run the application via JNLP

Right click the project and invoke Run JNLP Application – your NetBeans RCP application should now be started using the Java WebStart technology – and this is what we wanted to accomplish…

Development , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">