aspose file tools*
The moose likes Mac OS and the fly likes Eclipse and Java 5.0 on Mac Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Mac OS
Bookmark "Eclipse and Java 5.0 on Mac" Watch "Eclipse and Java 5.0 on Mac" New topic
Author

Eclipse and Java 5.0 on Mac

marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

I'm running Tiger (Java 5.0) on Tiger (Mac OS 10.4). Initially, I had some difficulty setting the "CurrentJDK" alias to the new version of Java (the 1.5.0 directory). This was solved as described here:

http://www.coderanch.com/t/111469/Mac/Java-Missing-Installation-Instructions

So Java 5.0 is working from Terminal (bash).

But now I've installed Eclipse 3.0.2, and it works fine until I attempt to compile Java 5.0 code (for example, autoboxing "Integer i = 7;"). When I do this, it's apparent that Eclipse is using a pre-1.5 compiler. So how do I configure Eclipse to use 1.5.0?

NOTES:
  • I've looked around in Eclipse (which I'm admittedly not very familiar with), but couldn't find any way to set this. The config.ini file in the Eclipse/configurations folder doesn't seem to store this variable.
  • My .bash_profile has JAVA_HOME set to /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin.
  • On the Eclipse Console toolbar (above the actual output area), it displays "<terminated> ... /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java" -- whether or not the code successfully compiles and runs (i.e., whether it's new Java 5.0 code that fails, or a safe Hello World that runs). So it seems that Eclipse is trying to use the .bash_profile variable, but terminates it and moves to a prior version instead.
  • With Java 5.0 code, the error message is consistent with a pre-1.5 compiler: "Type mismatch: cannot convert from int to Integer"


  • "We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
    sscce.org
    miguel lisboa
    Ranch Hand

    Joined: Feb 08, 2004
    Posts: 1281
    i'm not familiar with mac, but i guess you need eclipse 3.1;

    i had to use it in order to have tiger acess (see this thread)


    java amateur
    Rene Larsen
    Ranch Hand

    Joined: Oct 12, 2001
    Posts: 1179

    You need to use Eclipse 3.1 to be able to compile with Java 1.5 - by default.

    But maybe you can use this plugin Java 1.5 plugin - I have not tried it myself.

    Rene


    Regards, Rene Larsen
    Dropbox Invite
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    Okay, thanks. I see that Eclipse 3.1 isn't gold yet (they call it a "milestone" version), but I'll try it and post the result.

    http://www.eclipse.org/downloads/index.php
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    Unfortunately, Eclipse 3.1.0 did not solve the problem. The results are the same.
    Ben Poole
    Ranch Hand

    Joined: Jul 17, 2003
    Posts: 33
    The 3.1 releases definitely support Java 1.5... what issues are you having exactly? Is your project definitely set up to use the correct Java run time?
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    what issues are you having exactly?
    These are described in my original post at the top. Basically, Eclipse displays "<terminated> ... /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java" on the Console toolbar whenever I compile. If the code contains Java 1.5 features (e.g., autoboxing), then pre-1.5 compiler errors result.

    Is your project definitely set up to use the correct Java run time?
    This is exactly my question: What do I need to do to set it up for the correct compiler and runtime?

    I had concluded -- perhaps incorrectly -- that Java 1.5 for Mac is not supported by Eclipse 3.1, so any help would be greatly appreciated!
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    Here are some additional settings I've verified under Eclipse Preferences...
  • "Java/Installed JREs" shows the selected option as "JVM 1.5.0 (MacOS X Default)."
  • "Java/Build Path/Classpath Variables" indicates the correct version 1.5.0 paths for both JRE_LIB and JRE_SRC.
  • "Java/Compiler/Errors/Warnings" does show "JDK 5.0 options," and these all look okay.
  • I don't know what else to check. Everything appears to be configured correctly, but it's just not working.
    [ May 11, 2005: Message edited by: marc weber ]
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    Okay, I've got it -- Java 5.0 is now working in Eclipse!

    As described above, autoboxing simply wasn't working. So I tried some other 5.0 code (instances of Scanner, StringBuilder, etc.), and these worked. Then I tried the new "for each" loop, and this produced a warning icon that said I needed to change "workspace compliance settings to 5.0" or "project compliance settings to 5.0."

    Under "Preferences/Java/Compiler," I found the following settings...
  • Compiler compliance level: 1.4
  • Generated .class files compatability: 1.2
  • Source compatibility: 1.3
  • I changed each of these to 5.0, and now everything seems to work!

    (I really thought this was an issue unique to Java 5.0 on the new Mac OS, but it turned out to be my lack of familiarity with Eclipse. :roll: )
    [ May 12, 2005: Message edited by: marc weber ]
    Unnsse Khan
    Ranch Hand

    Joined: Nov 12, 2001
    Posts: 511
    Well, I did the same thing (setting up the compiler to point to JDK 1.5) and whereas the java.util.Arrays and java.util.queue (both from JDK 1.5 - Tiger) worked in Eclipse 3.0.1 running on OS X - Tiger, eclipse didn't understand Generics <SomeType>...

    Has anyone successfully written generics in Eclipse on OS X 10.4? And if yes, what version of Eclipse was this person using...
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    I believe you need version 3.1 of Eclipse in order to use all the new Java features.

    I don't recall if I've used generics on the Mac. I'm at work with a Windows machine now, but I'll try it tonight and post the result...
    Steven Bell
    Ranch Hand

    Joined: Dec 29, 2004
    Posts: 1071
    Just to clarify:

    Eclipse uses it's own compiler to build projects. This allows it to do many things (such as run a project that has compile errors, at least to some extent) that it could not otherwise do. Therefore you must have a version of eclipse that supports the compilation of the new Java 1.5 features.

    Eclipse 3.0.x does not support any of the new language features for Java 1.5, but if you have the 1.5 jdk installed it will see the new classes as they are on the classpath.

    Eclipse 3.1 is now in it's last milestone build, M7, and will have final release around the end of June (I think).

    Eclipse allows you to specify, per project, what compiler you want to use as far as Java version compatability goes. You can set the project to use the 'workspace settings'.

    Generated .class files compatability:
    refers to the lowest version of the JRE you want your compiled files to be able to run against. By default this is set at 1.2 so you can write and compile things in 1.5 and somebody running 1.2 can use them. I'm not sure how this works as far as the new classes goes, I think if you use any new classes the end user would need a version with those new classes in it.

    Source compatibility:
    refers to what Java version will be used to compile your source. This would need to be set to 1.5 in order for the new features to be available.

    If I've missed anything or gotten anything wrong, let me know.
    marc weber
    Sheriff

    Joined: Aug 31, 2004
    Posts: 11343

    Originally posted by Unnsse Khan:
    ... Has anyone successfully written generics in Eclipse on OS X 10.4? And if yes, what version of Eclipse was this person using...

    Generics seem to work fine using Eclipse 3.1.0 on Tiger 10.4.1.

    (In fact, when you type "class SomeGenClass <" Eclipse 3.1 knows to automatically add the closing ">" just like it does with method parentheses.)
    [ May 26, 2005: Message edited by: marc weber ]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Eclipse and Java 5.0 on Mac