New Maven Webstart Plugin

Ryan Sonnek bio photo By Ryan Sonnek

After uncovering the horrible state of affairs for Java Webstart developers, I spent some time trying to figure out where to go next. The current codehaus plugin for webstart projects just doesn’t cut it.

I was appalled that the default behavior of the plugin forced developers to manually create a JNLP file and all the plugin did was sign jar files and zip up the contents for you. After a few long discussions with the developers of the plugin, I commented that “It would greatly improve the adoption of this plugin if it supports very simple out of the box behavior”.

The response I was a bit surprising, “Not sure if that will improve the adoption of the plugin (what are the alternatives?)”

This got me thinking…What are the alternatives? This is exactly what’s going wrong with the maven community. There are no alternatives!

I spent the next two days hacking away at the current crappy maven plugin trying to contribute back improvements before thinking to myself, should it really be this hard? Can’t we provide drop dead simple support for 90% of webstart projects without jumping through all of these hoops? The current plugin is a mis-mash of partially implemented features and no clear usecase for how/when it should be used. The code is nearly unreadable and 100% untestable. Yuk…

So, I took a couple hours and whipped together a new maven webstart plugin that blows the pants off the current plugin. It handles the simple usecase with utmost ease and does so with less code and complexity. Less than 300 lines of code!

If you need complete flexability and control, use the codehaus plugin. If you want your project to “just work”, use mine. =)

The simple usecase is (you guessed it), very simple:

<build>
  <plugins>
    <plugin>
      <groupId>com.codecrate</groupId>
      <artifactId>webstart-maven-plugin</artifactId>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>generate-jnlp</goal>
           </goals>
        </execution>
      </executions>
      <configuration>
        <mainClass>com.mysite.MyApp</mainClass>
        <allPermissions>false</allPermissions>
      </configuration>
    </plugin>
  </plugins>
</build>

Now, if your application needs allPermissions, you just need to add information about what keystore to use for signing your jars. I’d recommend checking out the maven keytools plugin as well for helping setup and maintain your keystore.

<plugin>
  <groupId>com.codecrate</groupId>
  <artifactId>webstart-maven-plugin</artifactId>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>generate-jnlp</goal>
       </goals>
    </execution>
  </executions>
  <configuration>
    <mainClass>com.mysite.MyApp</mainClass>

    <keystore>${project.basedir}/src/main/webstart/keystore</keystore>
    <keypass>shard-rox</keypass>
    <storepass>shard-rox</storepass>
    <alias>shard</alias>
  </configuration>
</plugin>

Pretty much every part of the JNLP file is customizable through this plugin, but the key is that there are sensible defaults so you shouldn’t need to tweak anything else. But if you need to, here are some of the available switches:

Parameter Description Default Value
title Name of application project.name
description Description displayed when launching application project.description
homepage URL for the project homepage project.url
vendor Company publishing the application project.organization.name
codebase Base URL for JNLP resources project.url
jnlpFile Filename of the generated JNLP file launch.jnlp
spec JNLP spec version 1.0+
offlineAllowed Configure whether the application can be run offline false
j2seVersion Version of Java required to run the application 1.5+

You’ll also need to add the codecrate repository to have access to the plugin:

<repositories>
  <repository>
    <id>codecrate-repository</id>
    <name>Codecrate Repository</name>
    <url>http://maven.codecrate.com/</url>
  </repository>
</repositories>