29

I have a project in Eclipse which previously used JRE7 and referenced the JRE7 system libraries. I absolutely need it to now run in JRE6. I have not used any Java 7 specific syntax so the source code itself is entirely compatible. Here is what I have already done:

  • I Installed JDK6.
  • I then went to Window > Preferences > Java > Installed JREs and set JRE6 as default.
  • I configured the build path of my project to reference the JRE6 system library and not the JRE7 one.
  • Finally I went to Run Configurations > JRE and set it to run in JRE6.

Immediately after that last step, the top of the dialogue shows a message that says:

JRE not compatible with project .class file compatibility: 1.7

And when I run the project I get this error message:

java.lang.UnsupportedClassVersionError: ExampleProcessingApp : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:314)
    at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:146)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:608)
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:798)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:727)
    at sun.applet.AppletPanel.run(AppletPanel.java:380)
    at java.lang.Thread.run(Thread.java:679)

As I mentioned previously, the actual code of the project is no different from Java 6 syntax so it would run in JRE6. So presumably I need to somehow recompile all the .class files from the source code. I thought Eclipse would do this automatically. Any ideas?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Jonathan
  • 1,256
  • 4
  • 12
  • 18

6 Answers6

53

First, clean your project:

Project > Clean

If that doesn't fix things...

Second check your project specific java compiler:

Project > Properties > Java Compiler

Colin D
  • 5,641
  • 1
  • 23
  • 35
  • 1
    I actually already did the second step you mentioned but I didn't clean/rebuild my project and that seems to have fixed it. Thanks a lot! – Jonathan Jul 05 '12 at 23:23
12

The second method provided by Colin worked for me.

Here is a visual representation of all steps for that approach:

enter image description here enter image description here enter image description here enter image description here

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
3

I thought Eclipse would do this automatically. Any ideas?

No Eclipse does not clean all projects until you ask it to do so. It only cleans the generated class files of the sources you have modified. You should do a clean build of your solution, rebuild everything and run again, it should work just fine.

GETah
  • 20,922
  • 7
  • 61
  • 103
2

Thanks to all. Although it's solved, I would like to add another way of doing this to add another flavor.


It can be done by editing manually project preferences in file project_directory/.settings/org.eclipse.jdt.core.prefs and then refreshing the project in eclipse.

Change from 1.7 to 1.6

karimvai
  • 319
  • 3
  • 14
1

I've head a case where cleaning the project didn't solve the issue. I actually had to close and reopen the specific project to make it work.

Remo
  • 66
  • 4
1

Change Project->Properties->Java Compiler->Compiler Compliance Level

Shiv Buyya
  • 3,770
  • 2
  • 30
  • 25