Monday, November 16, 2009

Java Web Start – putting my application out there

I recently decided to write a small Java Web Start application using Groovy and Swingbuilder (and HttpBuilder). As i had no experience with Java Web Start, there was a bit of a learning curve. I knew that i would need signed jars in order for my application to be able to write to the local file system. However, a true signing certificate can be very expensive so i realized i would best serve my needs with a self signed certificate that i would keep renewing every 6 months. Using Ant, i have been able to have my app easily deployed with new signed jars.

It is important to mention that there is one simple solution that I did not use for my application, which is to use Griffon, as it takes care of all this stuff behind the scenes for you. However, since I had a simple application and had begun before i knew about it, I decided not to go this route and do it myself, which also ensures i have a better understanding of what is going on. Griffon will still be useful to you for reference. I especially found it useful to look over a sample jnlp file, the file used to list dependencies and configuration information

For signing the jars, i created a self signed certificate. However, every 6 months, i need to renew this certificate, which is pretty straightforward:
keytool -selfcert -keystore keystore -alias myAlias
After re-creating the certificate, i use ANT to sign and deploy. As Ant has a built in task for this, it is trivial:



   1: <target name="signJars" description="sign the jars" depends="makeJar">



   2:         <mkdir dir="signed"/>



   3:         <mkdir dir="signed/lib"/>        



   4:         <signjar destDir="signed"



   5:                  alias="mastertorah" keystore="keystore"



   6:                  storepass="changeit"



   7:                  keypass="mastertorah"



   8:                  >



   9:             <path>



  10:                 <fileset dir="dist" includes="**/*.jar"/>



  11:             </path>            



  12:         </signjar>



  13:         <signjar destDir="signed"



  14:                          alias="mastertorah" keystore="keystore"



  15:                          storepass="changeit"



  16:                          keypass="mastertorah"



  17:                          >



  18:                     <path>



  19:                         <fileset dir="dist" includes="**/*.jar"/>



  20:                     </path>            



  21:         </signjar>



  22:     </target>


In case you are wondering, line 3 above creates a second folder since my signed dependency jars sit separately from the main code; i just left this repeated signing command out of the snippet above.

As you see, line 4 uses the built in ant task signjar and it references my keystore. So, now i have a simple build process to easily redeploy my application.

For users reporting problems after deployment, one thing i have found helpful is to tell them to enable debugging, which is set in the control panel on Windows machines (in the java option there). This way they can send you a log of what went wrong.

I am left with one question. Why should i use SwingBuilder when i can drag and drop widgets using an IDE and get the format of my layout more simply.

No comments:

Post a Comment