Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 833
Jonathan Avatar asked Jul 05 '12 18:07

Jonathan


People also ask

How do I switch to Java 11 in Eclipse?

A Java 11 JRE is recognized by Eclipse for launching. It can be added from the Window > Preferences > Java > Installed JREs > Add... page. It can also be added from the Package Explorer using the project's context menu.


3 Answers

First, clean your project:

Project > Clean

If that doesn't fix things...

Second check your project specific java compiler:

Project > Properties > Java Compiler

like image 198
Colin D Avatar answered Sep 19 '22 12:09

Colin D


The second method provided by Colin worked for me.

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

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

like image 36
ROMANIA_engineer Avatar answered Sep 17 '22 12:09

ROMANIA_engineer


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.

like image 25
GETah Avatar answered Sep 21 '22 12:09

GETah