How do I convert my Eclipse project to an earlier Java version?

Jonathan picture Jonathan · Jul 5, 2012 · Viewed 33.7k times · Source

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?

Answer

Colin D picture Colin D · Jul 5, 2012

First, clean your project:

Project > Clean

If that doesn't fix things...

Second check your project specific java compiler:

Project > Properties > Java Compiler