It seems like this should be a simple task, with the options in the Preferences menu for different JREs and the ability to set different compiler and build paths per project. However, it also seems to simply not work.
For example, I have my JAVA_HOME set to a jre for Java 1.6. It's still not clear to me how Eclipse uses this, but it appears to be defaulting to this and not taking the project overrides. I have also installed Java 1.5, and added a JRE for this in eclipse in the Java->Installed JREs section.
In my project, I've set the compiler compliance level to 1.5. In the build path for the project, I've added the System Library for the Java 1.5 JRE. However, I'm getting compile errors for a class that implements PreparedStatement for not implementing abstract methods that only exist in Java 1.6 PreparedStatement. Specifically, the methods
setAsciiStream(int, InputStream, long) and setAsciiStream(int, InputStream)
Strangely enough, it worked when we were compiling it against Java 1.4, which it was originally written for. We added the JREs for Java 1.4 and referenced that system library in the project, and set the project's compiler level to 1.4, and it works fine. But when I do the same changes to try to point to Java 1.5, it instead uses 1.6.
Any ideas why?
Before exporting the jar file from eclipse select the version 1.6 or 1.7 rather than 1.8. Please follow the below steps: (i) Right Click on project and go to "Properties". (ii) Now Select "Java Compiler" and uncheck use compliance from execution.
A Java 11 JRE is recognized by Eclipse for launching. It can be added from the Window > Preferences > Java > Installed JREs > Add... page. It can also be added from the Package Explorer using the project's context menu.
From the menu bar: Project -> Properties -> Java Compiler
Enable project specific settings (checked) Uncheck "use Compliance from execution environment '.... Select the desired "compiler compliance level"
That will allow you to compile "1.5" code using a "1.6" JDK.
If you want to acutally use a 1.5 JDK to produce "1.5" compliant code, then install a suitable 1.5 JDK and tell eclipse where it is installed via:
Window -> preferences -> Installed JREs
And then go back to your project
Project -> properties -> Java Build Path -> libraries
remove the 1.6 system libaries, and: add library... -> JRE System LIbrary -> Alternate JRE -> The JRE you want.
Verify that the correct JRE is on the project's build path, save everything, and enjoy!
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