Running a J2SE 1.5/J2SE 5.0/Java 5.0/whatever Program From Command Line Under OS X

The good news is that J2SE 1.5 is available for OS X. Last I checked it was available here. For whatever reason Apple decided to keep the default version of Java on OS X as 1.4.2. So when I try to run Java programs directly from Terminal using "Java -Jar X.Jar" the program will be run under 1.4.2. But the goodies in J2SE 1.5 (like generics and enums and iterators) are just too yummy to give up so all my Java code is in 1.5 which means it won't run on Terminal. To fix this problem I found a script (details available here). Once I downloaded the script and saved it as java_functions_bashrc, I then opened terminal, navigated to the directory with the file and executed "source java_functions_bashrc". This changes the command prompt to indicate that the file is running and I then ran "setJava 1.5". At this point any Jar files I run will be run under J2SE 1.5. I tend now to write little scripts that wrap my Jar files to load up Java 1.5.

Leave a Reply

Your email address will not be published. Required fields are marked *