[Mac] Compile for Java5 with only a Java6 JDK

Hi,

I use Mac and Intellij Idea X.
Mac only comes with Java6 JDK (there are directories called 1.5, 1.4, and so on, but they are only symlinks to 1.6).
How can I compile/build Java code in Intellij to make it usable by a 1.5 JVM?

Thank you.

4 comments
Comment actions Permalink

Settings -> Compiler -> Java Compiler

You can use '-target 1.5' in the additional command line parameters.

But, the only way to be correct is to use a Java5 JDK. For that, you'll have to find and install an older JDK. I've got an old blog post on it here - Using Java 1.5 and Java 1.4 on Snow  Leopard - but I can't guarantee that it still works. I haven't needed or used an older JDK on OS/X for a while.

0
Comment actions Permalink

"But, the only way to be correct is to use a Java5 JDK."

Not really. But you have to be careful not to use any library calls that aren't supported in the older versions or you'll get runtime errors.
Developing against the older version turns those into compiler errors which is preferable of course but an IDE might be able to guard against that (I don't know how smart IntelliJ is when it comes to identifying calls to library methods that don't exist in the version you're intending to compile against rather than language features that don't exist in it (like generics when compiling against 1.4).

0
Comment actions Permalink

You can set language level (File | Project Structure | Project | Project language level) to 5.0 - IDEA will warn you about incompatible language features and API calls.

0
Comment actions Permalink

To install Java 1.5 on Lion you can follow these directions:

http://www.s-seven.net/java_15_lion

If you just need the files to compile against you just need to do steps 1 - 7. (the other steps are there if you need to run an application with Java 1.5)

Then  Java 1.5 home is:

/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home

0

Please sign in to leave a comment.