Ant build not working: unable to find a javac compiler
Solution 1
For eclipse
- Right Click build.xml ---> Build path ---> configure buildpath ---> select libraries tab
- click "Add library" ---> double click on [jre system library ] ---> environments ---> installed jres ---> Add ---> standard vm
- click on directory ---> Browse upto jdk [C:\Program Files\Java\jdk1.7.0_01]
- finish
- change the selection jre to jdk ---> click ok
Solution 2
Quick work around for the same is
Copy C:\Program Files\Java\jdk1.7.0_03\lib\tools.jar to C:\Program Files\Java\jre7\lib\
This exception is coming because JAVA_HOME is being set as C:\Program Files\Java\jre7 and Ant is not able to find tools.jar in it.
Solution 3
In windows, go to computer properties, advanced system settings, advanced, environment variables
Add a system variable called "JAVA_HOME" set its folder to your JDK location in my case "C:\Program Files\Java\jdk1.7.0_51"
Close command prompt, reopen it and it should work now.
Solution 4
When you have both JRE and JDK installed in your system, please make sure JDK comes first in your PATH variable.
I think system scans the PATH variable from left to right, whatever comes first is taken into consideration.
In my case (with LinuxMint ) I was getting the same error. When I added JDK in PATH variable before JRE , it solved my problem.
Solution 5
I was getting the same error in Mac OS X but all the answers I could find were for the Windows system and as the paths are a little different in both, those solutions weren't working for me. After spending hours on it, I was finally able to fix it in the following way:
Copy /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/lib/tools.jar to /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/ext
It will work for Windows users too:
Copy C:\Program Files\Java\jdk1.8.0_91\lib\tools.jar to C:\Program Files\Java\jre8\lib\ext
P.S. Also take care that the versions for jdk and jre that you have selected in Eclipse are compatible.
Comments
-
Eric Francis almost 4 years
I am trying to run some Java EE examples. Ant is suggesting:
Perhaps JAVA_HOME does not point to the JDK. It is currently set to "C:\Program Files\Java\jre7
My
JAVA_HOME
variable is:C:\Program Files\Java\jdk1.7.0_03
when I look at my windows 7 variablesHowever, my path is (notice the jdk1.6.0_26):
%M2_HOME%\bin;%ANT_HOME%\bin;%JAVA_HOME%\bin;%SystemRoot%\system32;%SystemRoot%; %SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\; C:\Program Files\Microsoft Application Virtualization Client;%M2%; C:\Program Files\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin; %GLASSFISH%;%GLASSFISH_PARENT%; PATH=C:\Maven\apache-maven-2.2.1\bin;C:\Ant\apache-ant-1.8.2\bin;**C:\Program File s\Java\jdk1.6.0_26\bin;**C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C :\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft Applicatio n Virtualization Client;C:\Maven\apache-maven-2.2.1\bin;C:\Program Files\QuickTi me\QTSystem\;C:\Program Files\TortoiseSVN\bin;C:\glassfish3\glassfish\bin;C:\gla ssfish3\bin;C:\Sun\jwsdp-2.0\jwsdp-shared\bin
Do I have to do anything special to get windows to save my path?
More Info:
C:\javaeetutorial5\examples\web\hello2>ant Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre7\li b\tools.jar Buildfile: C:\javaeetutorial5\examples\web\hello2\build.xml -pre-init: init: default-ear: -pre-compile: bpp-actual-compilation: [echo] Compiling hello2 [echo] javaee.classpath.prefix is: C:\glassfish3/lib [echo] is.glassfish.v3 is: ${is.glassfish.v3} [javac] C:\javaeetutorial5\examples\bp-project\command-line-ant-tasks.xml:93 : warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=las t; set to false for repeatable builds BUILD FAILED C:\javaeetutorial5\examples\bp-project\command-line-ant-tasks.xml:93: Unable to find a javac compiler; 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\jre7" Total time: 0 seconds