Saturday, March 19, 2005

Using Ant to build an executable Jar file

Boy... I am tired.  It is 3:09 pm in the afternoon and I have only been up for just over three hours today.  I dove deep into SWT and JFace last night.  I am really enjoying JFace at this point.  It really makes building a GUI application with SWT so much easier.

Anyway, at some point during the night, for whatever reason (can't remember now), I decided to setup a build.xml file for Ant.  I did this for two reasons:  1)  I wanted to learn more about using Ant and 2) I wanted to see if I could setup a build properly for the SWT/JFace application that I am working on.

The setup of the build.xml to do a clean compile and to build a simple jar file was quite easy.  The problem came in, however, when I tried to build an executable Jar.  I never could get things to work correctly.  I kept getting a message about java not being able to find the main class when I tried to launch the jar.

A little after 6:00 am this morning, I finally decided that I should get some sleep.  I guess that helped, because after sitting here for the past 30 minutes looking at it again, I figured it out.  Well, I figured it out by accident.  :)

I did a little reading on the Sun Developer Network forums and something made me look at another executable jar file that I know I have on my computer.  When I took a look at the manifest in the jar, I noticed that all of the files listed on the Class-Path entry were in the same deployment directory as the executable jar.  I had tried putting them in a path on the classpath and putting them in the jar, but that never did work this morning.

So, I said what the heck and copied the appropriate external jar files that I knew the project needed into the directory where my jar file was located.  Now, mind you, this is the same jar that had just 30 seconds earlier given me that same “Cannot find the main class” error message.  After copying the files, I tried to launch the jar again and to my surprise, my application came right up.  Sweet!

I hate that I have wasted most of a Saturday, but I have definitely learned a lot about Ant and creating executable jar files in the past 18 hours.

Technorati Tags: , , ,

No comments: