Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying minor version in JDK Compliance eclipse

Tags:

java

eclipse

My JDK version is jdk1.8.0_45 and I have built an application using the default JDK Compliance setting in eclipse.

But my colleague is having a JRE with version jre1.8.0_20. So when my application is run in his system, it is throwing an

java.lang.UnsupportedClassVersionError Unsupported major.minor version 52.0

If I build the application with JDK compliance set to 1.7, it works fine obviously. But I don't want to lose all the features of JDK 8 just for a minor version mismatch.

And in eclipse I am not able to set a minor version compliance level. Is it possible to set it???

Or is Java forward compatible with minor version releases?? If so, obviously this error should not occur I believe.

like image 501
Codebender Avatar asked Jul 01 '15 12:07

Codebender


People also ask

How do I change the default Java version in Eclipse?

Configure the default JRE Download and install a Java JDK v1. 7 or greater. Set it as the default in Eclipse by selecting Preferences -> Java -> Installed JREs. Add the installed JDK and select the checkbox, making it the default.


2 Answers

According to this Version 52.0 is JDK-8. It seems that its a Number compiled into the .class files depending on the JDK. JDK-7 has 51, JDK-6 has 50 etc.

I would state the execution on your collegue's machine didn't use a JDK/JRE 8.

Try running java -XshowSettings on your collegues pc and check the output of the line java.class.version - if its a JDK 7 it will show java.class.version = 51.0.

like image 153
hinneLinks Avatar answered Sep 22 '22 00:09

hinneLinks


You should be specifying a runtime "Execution-environment" version dependency rather than a specific java version.

For a plugin, in the manifest.mf, specify execution environment: JavaSE-1.8

For a plain java project, in "Build Path...->Configure BuildPath" go to "Libraries" then "Add Library", "JRE System Library", "Execution Environment" and select JavaSE-1.8. Remove any other JRE on path.

This says to eclipse, find a Java >= 1.8 compliant JRE.

like image 30
Yann TM Avatar answered Sep 19 '22 00:09

Yann TM