Eric Francis
Eric Francis

Reputation: 24307

Ant build not working: unable to find a javac compiler

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 variables

However, 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

Upvotes: 21

Views: 83401

Answers (8)

Kirthi
Kirthi

Reputation: 13

This worked for me. Even after adding tools.jar if it shows that javac not found. Click on run-> external tools configuration -> jre -> seperate JRE make sure points to jdk -> apply -> run And then run the build.xml file Jusy make sure in installed jre you are pointing to jdk location. Hope this helps

Upvotes: 0

developer
developer

Reputation: 678

Got this error in Ant command line on Windows 7 x64 system.

Below change fixed the issue

Installed JDK from Oracle servers and then added a new system variable JAVA_HOME with value C:\Program Files\Java\jdk1.8.0_131

Upvotes: 0

Anna Shekhawat
Anna Shekhawat

Reputation: 181

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.

Upvotes: 3

TANMAY
TANMAY

Reputation: 31

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.

Upvotes: 3

minhas23
minhas23

Reputation: 9671

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.

Upvotes: 21

Shai Petel
Shai Petel

Reputation: 316

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.

Upvotes: 4

BavaMars
BavaMars

Reputation: 11

When you click on the next button in the JRE Type window after selecting Standard VM you go to the next window named JRE Definition where you can find the Directory button.

Upvotes: 1

Arunsg
Arunsg

Reputation: 434

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

Upvotes: 41

Related Questions