For some time I tried to understand, but I still don't get exactly what "compiler compliance level" for a project in Eclipse means. I looked all over this site and Google and couldn't find an answer I could understand.
Let's say I want my program to be able to run on JRE 6.
I can do: Project > Preferences > Java Build Path > Libraries, and set the JRE library I use to JRE 6.
Why isn't this enough?
I never understood why I also need to set the compiler compliance setting to JRE 6.
I'd like to understand the difference between using JRE 6 in a project, and setting the project's compiler compliance setting to JRE 6.
What exactly does compiler compliance level mean?
The Compiler Compliance level tells Eclipse to use appropriate settings when compiling your project to ensure you code will work on the target JVM you specify. By default, if I recall, Eclipse picks Java 5 Compliance.
To configure compiler compliance level and settings in eclipse, find the below steps. Step 2: Go to Java -> Compiler . Find the print screen. Step 4: To change default compliance settings, we need to uncheck Use default compliance settings and set the compiler java version for .
In summary, Eclipse uses its own JDT core as the Java compiler. The JDT core compiler does not have a JRE. So Eclipse requires user installed JRE to run the .
The compiler compliance setting tells the compiler to pretend it's a different version of Java. The Java 8 compiler will produce class files in the Java 8 version of the class file format, and accept Java 8 source files. JRE 6 can't load this version, because it was created after JRE 6 was.
To summary, here are the steps to change Java compiler version for a project in Eclipse IDE: Install JRE/JDK that supports the Java version you want to use. Update Java Build Path for the project, pointing to the new JRE/JDK Change Java compiler compliance level.
By setting the compliance level to 1.6, Eclipse will allow you to use API/methods that were introduced in 1.6 in your project, this code will only work if executed with a 1.6 VM, you would likely get a NoSuchMethodError if you run it with a 1.5 series VM or it is possible that you get the class version error and the classes will not even load.
If you right click on your project and go to Properties > Java Compiler. It will show you the compiler compliance level is 1.5 because you have selected the J2EE Specification Level as Java EE5.0. You can set your Compiler’s JDK compliance here – From MyEclipse menu options click on Window > Preferences > Java > Compiler.
The compiler compliance setting tells the compiler to pretend it's a different version of Java.
The Java 8 compiler will produce class files in the Java 8 version of the class file format, and accept Java 8 source files. JRE 6 can't load this version, because it was created after JRE 6 was.
If you set the compliance level to "JRE 6", it will instead compile Java 6 source files into Java 6 class files.
It's like saving a Word document as "Word 97-2003 format" - so that Word 97-2003 can read your document. You're saving the class files in Java 6 format so that Java 6 can read them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With