Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Java - Set compiler to Java 6 but still have Java 7 methods/libraries and no complains

For a project I must use Java 6, so I set my eclipse compiler setting to 1.6 (JDK compliance level).

However, I included java.nio.file.Files which is a Java 7 library and I am not getting any complaints. I can ensure that my project specific setting is set to 1.6. I even changed my entire workspace to 1.6 and rebuilt, still no complaints. My colleagues are seeing the complaint on java.nio.files.

Is it becuase I have a jdk7 which is recognizing the java.nio.file.Files even when set to 1.6 spcs?

like image 977
Allen H. Avatar asked Aug 03 '26 18:08

Allen H.


1 Answers

These are two different things:

  • the compliance level is about the syntax that you can use when writing Java code (respectively about the Java version number that gets put into compiled byte code)
  • but the libraries that are available to you depend on the JDK that your project is using!

In other words: if you truly want to restrict your project to Java 6 libraries, you will have to install a Java 6 JDK on your system, and point to that within your project setup ( most likely, your current project setup makes use of a newer-than-Java-6 JDK ).

And the usual disclaimer: Java 6 has had end of life many years ago. You should do whatever you can to upgrade your setup.

like image 61
GhostCat Avatar answered Aug 06 '26 06:08

GhostCat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!