Tuesday, January 02, 2007

Running my Java 5 App on MacOS X

I've written a simple app for my wife in Java (using Netbeans Matisse). I've got an XP laptop which I use to develop on. Running it was simple within the IDE and I created a simple zip file containing my jar, the required libraries and the derby database files and a .bat file to make running it a double click affair. How hard could it be to move it to her Mac?

Being quite simplistic about it and having worked at Sun in the past (Unix is Unix right?) I thought I could create a simple .sh equivalent of the .bat file to protect my beloved from the intricacies of the "java" command. Before this I thought I'd just try out the command at the terminal to check it worked. Best practice you see...

Wrong. I kept getting errors about my jar files (all of them) not being excutable ("cannot execute binary file"). My first thought was that it was a Windows / Mac newline thing... nope. Corrupted JAR files?.. Nope. Then I found a blog entry about how my problem was common and you needed to wrap things in a shell script. I did, and then started getting all manner of even wierder errors (most likely due to my terrible korn shell skills rather than anything else). I was stuck but had the distinct feeling that there was a very simple solution.

There was. I had my classpath seperated with ";"'s. Macs don't like that (I'd forgetten that other unixes don't either - so much for my Solaris skills) and need ":"'s instead. Dammit. Now she runs like a dream (and looks sweet too with the default MacOS X liquid look and feel...

3 comments:

Steve Jones said...

Oh dear Andrew, hang your head in shame. ";" is the unix command separation symbol, as in "javac x.java; java x".

This is as old as the hills in terms of windows<->unix portability. This isn't a Java problem its a Unix/Windows problem.

Anonymous said...

Hi Andrew, could you check out a career opportunity you may be interested in?

http://www.linkedin.com/jobs?viewJob=&jobId=213777

Also on my weblog: http://blog.meta-resourcing.com/?p=6

Let me know if you are interested - it's with one of the big 5 - not Cap!

Kind regards,

James Waite
07766 945733
james@meta-resourcing.com

Anonymous said...

Thanks this tip helped :)
/me too shaks head in shame!