3

I have been receiving the following error on eclipse when i try to build an ant project

com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre-10.0.2"

but my JAVA_HOME variable is set to C:\Program Files\Java\jdk-10 this is the result of the command echo %JAVA_HOME% i really tried a lot to solve this problem ,but i don't know much about eclipse,

Edit: i searched some more on the internet and found out that the tools.jar has been removed from the JDK since JDK 9 [link]https://www.reddit.com/r/javahelp/comments/765mwr/installed_jdk_9_and_my_toolsjar_is_missing/ the question now is why is eclipse asking for the tools.jar ,and what is tools.jar replacement ?

I would really appreciate any help thank you very much

jjdoedoe
  • 43
  • 1
  • 4
  • 2
    Possible duplicate of [Unable to find a javac compiler com.sun.tools.javac.Main is not on the classpath error](https://stackoverflow.com/questions/29668849/unable-to-find-a-javac-compiler-com-sun-tools-javac-main-is-not-on-the-classpath) – KevinO Oct 04 '18 at 03:49
  • @KevinO not really i tried all the solutions in that thread none worked but ,apparently, tools.jar has been removed from the JDK since JDK 9 [link ]https://www.reddit.com/r/javahelp/comments/765mwr/installed_jdk_9_and_my_toolsjar_is_missing/ , now the question becomes what is tools.jar replacement ? – jjdoedoe Oct 04 '18 at 10:43

2 Answers2

4

In Java 9 and later, the components that were previously in tools.jar have been turned onto modules. For the javac compiler, you need to use the java.compiler module. This is not a simple drop-in replacement.

If you run into problems with a 3rd-party application (such as Ant) that depends on tools.jar, you need to upgrade the application to a newer version that is Java 9+ compatible.

According to my reading of the Apache Ant site, that means you need Ant 1.10.x. Check the site's download page to see what is currently recommended.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • you are right, but it wasn't the ant it was eclipse, i just had to use a version that is compatible with jdk 10, so i deleted my eclipse and downloaded the latest version of eclipse photon ,this seem to have solved the problem,thank you very much for your help – jjdoedoe Oct 04 '18 at 21:00
  • I have ant version 1.10.5 – jjdoedoe Oct 04 '18 at 21:07
  • It would have been the version of Ant that is embedded in your (old) Eclipse install ... which Eclipse uses to do Ant builds. – Stephen C Mar 23 '20 at 07:08
  • 1
    In case it helps anyone: The `java.compiler` module does not contain `javac` itself, but rather _uses_ `javax.tools.JavaCompiler` which the `jdk.compiler` module _provides_. – Slaw Aug 21 '20 at 07:31
-5

If you are using openJDK11 you can probably use lib/jrt-fs.jar as a replacement of tools.jar

  • 1
    Bad guess. The jrt-fs JAR is something completely different; see https://openjdk.java.net/jeps/220 for an explanation of it really is. – Stephen C Mar 23 '20 at 07:15