The road so far….

April 2, 2010

JNLP: Delivering client-side Java programs using browser

Filed under: java, maven — Tags: , — Rahul Sharma @ 5:30 pm

Recently we made a swing application for one of our clients. It was meant to be just a tool for the APIs that we wrote for the client, to facilitate the business people to get a hand of the system. But now as with most of the projects the requirement changed. The UI that we made was meant to work over browser and should be available over intranet. This was a complete surprise for us, as now the application needs to be converted from Swing to Applet, which is a bit unstable as it gives its own set of security concerns.

Not feeling quite optimistic about converting the UI I started to look at options that can help us out to put desktop application on browser. It was then I started playing with Java network launch protocol(JNLP) and Java Webstart.

Unlike other browser-based applications Webstart applications run outside the browser but are delivered through a standard Web server. These applications get downloaded on client machine then get installed and run from the local client machine. You can have newer version of a Webstart application and it will get downloaded on the client automatically , whenever the client runs it the next time.

Now in order to convert a standard java application to a Webstart application you need to do quite some work as specified by SUN tutorial. Following are the steps in brief:

  1. Generate a key
  2. Create a JNLP specification file
  3. Pack the whole stuff in a jar
  4. Sign the Jar using the key
  5. create a war for the application using signed jars
  6. Deploy it into a web server.

Or we can use the maven webstart plugin for generating the signed jars and maybe use assembly plugin to get a deployable War. The plugin works quite out of the box with some initial configuration as specified on the plugin page. It has its own set of sample templates that can be used to generate the JNLP file for the application.

Following is the snapshot of the configuration that I used to generate the signed jars.:

<plugin>
<groupId>org.codehaus.mojo.webstart</groupId>
<artifactId>webstart-maven-plugin</artifactId>
<configuration>
<dependencies>
<includes>
<include>commons-lang:commons-lang</include>
<include>commons-io:commons-io</include>
</includes>
</dependencies>
<jnlp>
myApp.jnlp <!– defaults to launch.jnlp –>
<mainClass>com.sample.HelloWorld</mainClass>
</jnlp>
<sign>
<keystore>pass</keystore>
<keypass>pass</keypass>
<storepass>pass
<alias>hello</alias>
<dnameCn>MyName</dnameCn>
<verify>true</verify>
<keystoreConfig>
true <!– delete the keystore –>
<gen>true</gen>       <!– optional shortcut to generate the store. –>
</keystoreConfig>
</sign>
<pack200>true</pack200>
<gzip>true</gzip>
<outputJarVersions>false</outputJarVersions>
</configuration>
</plugin>

The plugin works with webstart :jnlp goal. Then I packed the jars generated using the assembly plugin and integrated it into the build.

The plugin also provides a mechanism to configure JnlpDownloadServlet class that can be used to generate Wars which can automatically suit to your context path. It has a sample template which can be used with the webstart:jnlp-servelet goal. But I faced some issues with it and was unable to use it successfully. With the task of generating this War as time-boxed I resorted to my earlier attempt of using webstart:jnlp goal along with assembly plugin and integrated it into build process.

PS: If someone is able to work with JnlpDownloadServlet using webstart plugin do tell me 🙂

Resources:

http://java.sun.com/developer/technicalArticles/Programming/jnlp/

http://mojo.codehaus.org/webstart/webstart-maven-plugin/

http://java.sun.com/javase/6/docs/technotes/guides/javaws/developersguide/downloadservletguide.html

Advertisements

9 Comments »

  1. Consider using the shade-plugin to build a single jar composing all dependencies in your client app. Then include your client component as a dependency in your web app pom.

    Pull the jnlp-servlet dependency from the JDK version you’re using, and add it as a dependency. Hopefully, you’re using Nexus as a local network Maven repository, to which you can add the jnlp-servlet.

    That said, best of luck. The webstart implementation is so broken as to be useless for most developers. For instance, auto-update does not work via a webstart-enabled web app, at least not for me.

    I’ve moved on to providing a downloadable executable jar via a web page. The standalone client simply communicates with a web app via a Spring HttpInvoker. It works beautifully. I sure wish webstart did.

    Hope that helps a bit.

    Comment by Mike — April 30, 2010 @ 12:46 am

  2. JnlpDownloadServlet… I do. What do you need?

    Comment by davidecr — April 30, 2010 @ 12:47 am

    • Thanks for reponding. We were trying to use webstart:jnlddownloadservelt goals of maven. But I believe when you have third party signed jars then you need to have a seperate JNLP file for each of them as not doing so gives you all sorts of errors sysing “jars are not signed by the same key”. We were unable to integarte this in maven build process using webstart:jnlpdownloadservlet goal.

      Comment by Rahul Sharma — April 30, 2010 @ 9:34 pm

      • @Rahul Sharma : I don’t understand .

        I have successfully integrated jnlp-download-servlet from maven webstart.

        It’s not very well documented, but you can handle all cases of delivery.

        For my application, I’ve created a keystore and I don’t delete it after delivery. So Jars are always signed by the same key.

        Comment by Fabien Charlet — March 30, 2011 @ 1:28 pm

      • Hi Fabien
        Actualy what I remember now was that we had some third party jars that were alredy signed. In such a case we need to have them in a seperate JNLP file. If you have a configuration in which you can somehow use third party jars signed by a differnt key in the same JNLP file I would like to know that. But I think that is not possible.

        Comment by Rahul Sharma — April 1, 2011 @ 12:35 am

  3. […] Java Webstart: delivering client-side java programs using browser […]

    Pingback by todays links | Ani's Geeky Blog — April 30, 2010 @ 4:21 pm

  4. […] This post was mentioned on Twitter by Richard Laksana. Richard Laksana said: Java Webstart: delivering client-side java programs using browser – http://su.pr/17S9tM […]

    Pingback by Tweets that mention JNLP: Delivering client-side Java programs using browser | The road so far…. -- Topsy.com — May 1, 2010 @ 2:46 am

  5. Great post, I voted for it on Digg

    Comment by Jerrell Lafler — May 26, 2010 @ 8:40 am

  6. Hello, I found this post via google. Great post and materials.

    Comment by szczyrk — June 23, 2010 @ 4:07 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: