Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "compiler compliance level" in Eclipse?

Tags:

java

eclipse

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?

like image 705
Aviv Cohn Avatar asked Mar 22 '14 22:03

Aviv Cohn


People also ask

What is compliance compiler?

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.

How do I check my complier compliance level in Eclipse?

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 .

Which compiler is used in Eclipse?

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 .

What does the compiler compliance setting do?

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.

How to change Java compiler version in Eclipse IDE?

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.

What is the compliance level in Eclipse?

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.

How do I know if my compiler is J2EE compliant?

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.


1 Answers

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.

like image 138
user253751 Avatar answered Oct 06 '22 00:10

user253751