1

I was trying to compile a Grails application referencing third party JARs on Mac OSX. Although my system's JRE and JDK is set to Java 1.6 I always got a Compilation error: java.lang.UnsupportedClassVersionError: Bad version number in .class file when accessing classes in the JAR. Also when testing an existing Grails app the default stats of the app where showing that it's running with Java 1.6. So I really didn't have more ideas than to try to change the Java settings in Eclipse - I thought that's stupid as I'm not using Eclipse for the devlopment of this application - but voila - now the compilation of my app on the command line works just fine!

Can anyone explain me what Eclipse is doing here behind the scenes? I've had set the JAVA_HOME manually before with no effect.

david
  • 2,529
  • 1
  • 34
  • 50
  • > I just changed the default JRE in Exclipe: if you are referring to the declared "installed JRE" that should not have any side-effect (except recompiling existing projects referenced in Eclipse... but you said you have none? So why Eclipse was opened in the first place?) – VonC Sep 16 '09 at 08:34
  • Opening Eclipse (and further development in Eclipse) was the last idea I had as the env vars are handled differently in eclipse - but I didn't even come to the point to compile it in Eclipse - I just changed the default JRE setting in Eclipse to 1.6 (the command line JAVA_HOME was already 1.6 before) and then tried (without much hope) to compile it on the command line again - and it worked. I can't explain myself. – david Sep 16 '09 at 09:18

1 Answers1

4

The JDK (JAVA_HOME) used to launched eclipse is not necessarily the one used to compiled your project.

To see what JRE YOU y can select for your project, check the preferences

General > Java Installed JRE

By default, if you have not added any JRE, the only one declared will be the one used to launched eclipse (which can be defined in your eclipse.ini).
You can add any other JRE you want, including one compatible with your project.

http://help.eclipse.org/juno/topic/org.eclipse.jdt.doc.user/tasks/images/task-add_jre_std_vm.PNG

After that, you will need to check in your project properties (or in the general preferences) what JRE is used, with what compliance level:

http://www.standartux.fr/public/Java/Preferences.png

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for you fast reply but I was not using Eclipse for that specific project before - Command Line and TextMate only! Here the compilation did not work because of an "Bad Version" error as I would run a Java 6 project with Java 5. But I didn't - everything looked like Java 6. But then I did the same what you have mentioned - I just changed the default JRE in Exclipse but did NOT import the project to eclipse and did NOT compile it using eclipse. I was still compiling from the command line with "grails compile" - and now the compilation suddendly succeeded without any errors. Sounds strange. – david Sep 16 '09 at 08:21