0

This issue is atleast 8 years old but has no clear solution till now and has been asked multiple times on SO relevant to different JDK installations again and again

the solutions proposed are no more relevant to latest Java releases since release 10 since the entire compiler structure has been revamped.

All the 3 solutions offered in the older QA

  1. setting JAVA_HOME correctly
  2. adding tools.jar to my maven dependency list
  3. running eclipse with correct vm

do not seem relevant/work anymore.

I tried all the above 3 with jdk 14 including adding the following dep to my pom as explained else where

<dependency>
 <groupId>jdk.tools</groupId>
 <artifactId>jdk.tools</artifactId>
 <scope>system</scope>
 <systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>

What would be the ideal solution when using JDK 14 and above while my source / target version is set to 1.8

Gautam
  • 1,030
  • 13
  • 37
  • 1
    *Ideal solution:* Upgrade code to use the newer built-in Java compiler. – Andreas Jun 02 '21 at 11:38
  • does it mean latest JDK is not expected to support 1.8 anymore ? I am certain billions of LOC still needs to be supported on 1.8 while running JVM 14 – Gautam Jun 02 '21 at 11:40
  • That is correct. If your code uses features in the runtime library that has been removed, like JAXB in Java 11 and JavaScript is Java 15, then the code won't run without you adding those features back in as third-party libraries, which is e.g. easy for both JAXB and Nashorn. – Andreas Jun 02 '21 at 11:49
  • Ok. I hope someone has a workaround to help build 1.8 code with jdk 14 / 15 – Gautam Jun 02 '21 at 11:59
  • 1
    If you are compiling for Java 8 it is much simpler just to use a Java 8 JDK for the project. Just because Eclipse itself is running on a newer Java doesn't mean you can't use an older Java for a project. - See the project properties and the Installed JREs Preferences page. – greg-449 Jun 02 '21 at 12:15
  • yes I did try using jdk 1.8. The problem is if I do so, I must add the tools.jar to my maven pom as a dependency and we have developers that work with different platforms linux / mac / win . and it doesn't allow me to use $JAVA_HOME in specifying the path. – Gautam Jun 02 '21 at 12:18
  • 2
    Isn't that what the toolchains file is for? https://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html – nitind Jun 02 '21 at 12:23

0 Answers0