Jonathan
Jonathan

Reputation: 1286

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:

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?

Upvotes: 29

Views: 47075

Answers (6)

Shiv Buyya
Shiv Buyya

Reputation: 4130

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

Upvotes: 1

karimvai
karimvai

Reputation: 319

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

Upvotes: 2

ROMANIA_engineer
ROMANIA_engineer

Reputation: 56636

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

Upvotes: 12

Remo
Remo

Reputation: 66

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.

Upvotes: 1

Colin D
Colin D

Reputation: 5661

First, clean your project:

Project > Clean

If that doesn't fix things...

Second check your project specific java compiler:

Project > Properties > Java Compiler

Upvotes: 54

GETah
GETah

Reputation: 21409

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.

Upvotes: 3

Related Questions