Java programming and Mac OSX

 I am currently developing a Java application involving ontologies for a professor at Texas State University.  The decision to use Java is due to the long-term goal of implementing a multi-agent system involving the Jade Framework.  In addition, Java also has the added benefit of being a multi-platform programming language..... or is it?  The professor I work for prefers to use his MacBook; therefore the application I write needs to run on it.  Not long into development I found out that a Java application developed on a Windows based computer, does not automatically run on a Mac.  In this post, I'll discuss why it didn't and how I fixed the problem.

My development environment was a Windows XP machine, provided by Texas State, running Eclipse and Java 1.6.  The application I was writing worked just find on Windows and Linux.  However, the error report came in that it did not work on Mac OS X 10.5.6.  After some research I discovered that that particular version of Mac OS X supported Java 1.5.  (To determine what version of Java is supported by your operating system, from a command prompt, console window, or terminal window type "java -version".)  It took some playing around and help from folks on the Eclipse forums, but I figured out how to create a Java application that runs on Mac OS X.

Eclipse has a number of settings in terms of Java versions.  But the first thing for developing a Mac OS X compatible application on a Windows based computer is to download a Java 1.5 version JDK or JRE from the Sun website.  Once you have done that you'll need to let Eclipse know that it is there.  To do so, in Eclipse, click on Windows -> Preferences; click on the plus (+) sign next to "Java" and then click on "Installed JREs".  This screen shows the Java installations that Eclipse is aware of.  If Java 1.5 is not listed here, click on "Add", choose "Standard VM", then, after clicking next, specify the JRE home by using the "directory" button to direct Eclipse to the folder containing the Java 1.5 JDK or JRE on your machine.

Once Eclipse knows that you have Java 1.5 (or another version of Java) installed on your computer, you can set any project to use that version of Java.  To do that, in your Java project go to the "Configure Build Path" options screen.  On the "Libraries" tab select the "JRE System Library" and click on "Edit".  I selected the radio button for "Alternate JRE" and chose the Java 1.5 JDK.  (Note: An update Mac OS X version will support Java 1.5.0_22.  However, older versions of OS X may only support Java 1.5.0_13.  There may not be a lot of difference, it could still result in problems running your Java application on a Mac computer.)  

Once you've modified the Java System Library version in the "Java Build Path" there is one more thing to check.  In the Eclipse Java project build path settings, go to the "Java Compiler" settings. For the "Compiler compliance level" select 1.5; this will let Eclipse warn you if you are using anything that does not work in Java 1.5.

These are the steps it took for me to be able to compile a Java runnable JAR for Mac OS X.  If you are having any problems in this area, feel free to leave a comment and I'll see if I can help.  If you are using Eclipse, the forums there were of great help to me.  Also, if anyone is interested to hear about my work with ontologies and Protege, or with Jade and multi-agent systems let me know; I can post information about that as well.