Apache Batik with Maven 2

Today I just wanted to try some SVG graphics within a new Swing application.  The build is based on Maven 2 and so it should have been relatively easy to add the stuff to the project . . .

I checked the Fornax Respository and found about 18 Artifacts! Hmmm . . . Which one to use? Most of them don’t have any dependencies inside. Finally I discovered that it’s the Batik SVG Rasterizer that has the necessary declarations inside. 

Additionally I added Batik Swing because it sounds like I’d need it inside a Swing application 😉

I started the application and got a 

java.lang.NoClassDefFoundError: org/w3c/dom/svg/SVGSVGElement

Exception . . .

It took me some time to find the necessary XML APIs within the Maven respository but at least I succeeded…

Here are my Maven dependencies – Maybe this will save you some time:

<dependency>
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis-ext</artifactId>
    <version>1.3.04</version>
</dependency>
<dependency>
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <version>1.3.04</version>
</dependency>
<dependency>
    <groupId>batik</groupId>
    <artifactId>batik-rasterizer</artifactId>
    <version>1.6</version>
</dependency>
<dependency>
    <groupId>batik</groupId>
    <artifactId>batik-swing</artifactId>
    <version>1.6</version>
</dependency>

A better Java Webstart for standalone apps

Webstart is a nice solution for deploying Java applications. But when it comes to a corporate environment, it has a not-so-small problem: The Java Runtime System itself!

If several applications share the same Runtime, you may get into version trouble—Some applications want to have the latest Java version to fix some bugs. Other applications don’t want to update because they fear incompatibilities. Or there is simply no budget for regression testing all applications with a new Java version.

Some of you may argue against it because Java has claimed to be always backward compatible—But believe me, that’s not true. I took part in three version updates 1.3=>1.4=>1.6 and there were always changes in the behavior of the UI that need to be addressed!

In my opinion, an optimal Java (standalone) application is simply copied into a local directory and has its own Java Runtime inside this directory. That way, it can be easily removed by simply deleting the directory, and it no side effects occur with different JRE versions or with the OS environment in which it’s running.

But how do we update such an installation?

We simply use Webstart as a kind of Bootstrap Loader!

The process should be as follows:

  1. Start a generic updater with Webstart.
  2. The updater refreshes all changed JAR files of your application. This may even include the JRE itself that lives inside the application directory.
  3. Finally, the updater starts your application using the local Java Runtime.

That way you have best of both worlds: The updater itself is updated with the standard Webstart mechanism, and your application runs completely independent from the environment. A nice surplus is that you no longer need to sign your JAR files because the main program is no longer a Webstart application (only the Generic Updater needs to be signed).

If I can find some spare time over the next few weeks, I’ll try to create a small prototype of the generic Updater . . .