Java and Technology weblog
I have spent the last few weeks struggling with a Swing app that I wanted to deploy via Webstart and build using Maven, via the the Webstart Maven Plugin. It has been a hugely painful process. I found the plugin documentation difficult to follow, struggled to understand the subtle config differences in jnlp, took longer than I expected to get jar signing working, had problems with webstart caching and suffered through a plethora of vague error messages. I found this posting where the author vowed to never use Webstart again, and I can empathize. Postings of people asking for help with Webstart problems certainly aren’t difficult to find. Using maven to build the jnlp provides some conveniences, but introduces new problems too. Overall, I’d prefer to avoid using a Swing/Webstart/Maven solution again.
I did finally get everything up and running. You can skip ahead to my next post about the final working solution. Otherwise read below for the various options I experimented with before first, but either couldn’t get working or chose not to use.
1) Putting the jnlp details directly in the web module
I had the idea that putting the jnlp details directly in the web module so that when it came to generating the web module war, it would already contain the jnlp bundle, making deployment to the server easier. See my attempted solution here.
And I did get this solution working – for this simple example.
The issue I ran into was when I tried to extend the example to my real project which uses versioning (via the maven release plugin). As soon as I tried using version numbers other than 1.0 all round, I had issues, specifically with the jnlpFile/jarResources/version section. The web module suddenly had difficulty finding the client artifact in the maven repo. I suspect it was attempting to download the artifact before it had actually been deployed to the repository. I’m sure there is a way to make this solution work, but I couldn’t figure it out.
2) Bundling the jnlp files in a war using the dependency-maven-plugin
I tried following this example for the client, and this example for the web module which uses the dependency-maven-plugin with the objective of packaging up the JNLP bundle with the web’s module war to produce a single war that could be deployed to tomcat. See my attempt here.
The issue that I ran into was that the jnlp folder gets generated in the client target directory (e.g. SwingWebstartMaven\SwingWebstartMaven-Client\target in my example), but only the contents of the target/classes directory actually seemed to get copied to the web module. I tried working around this by modifying the client to generate the jnlp in classes directory e.g.
But then I seemed to run into issues with the webapp module being built before the client module.
Again, I’m sure there is a way to make this solution work, but I couldn’t figure it.
3) Use assembly plugin to combine client and web module outputs
I spent some time looking into this example which suggests creating a new module (which it calls webapp-bundle) whose sole purpose is to combine the output of the client and web modules by using using the maven-assembly-plugin. It aims to combine the web module’s war with the client module’s zip into a single deployable war.
I think this is probably a viable solution, but mid way through I decided it was just going to be easier to take the existing zip that is generated by the client module and unzip it to the application server (e.g. tomcat/webapps). That is basically what I did in my final solution. See my next posting for the details.
Some useful bookmarks
JNLP goals overview
Gives 2 pom examples, one using jnlp, jnlp-inline or jnlp-single goal and one using the jnlp-download-servlet goal
- JNLP Download Servlet example
I omitted the from the example in my next posting, but I did end up using it in my real project. This link shows how to incorporate the JnlpDownloadServlet into your project. At time of writing the servlet wasn’t available in many nexus repos, so you will likely need to install in your local repo yourself.
- JNLP 101
Some things that are not directly related to the Webstart Maven Plugin but can help you make good use of it.
- JNLP File Syntax
Oracle page describing the JNLP file elements.