Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant build not working: unable to find a javac compiler

Tags:

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 
like image 950
Eric Francis Avatar asked Mar 29 '12 17:03

Eric Francis


People also ask

Where is javac compiler located?

The value that you want to add is most likely C:\Program Files\Java\jdk-14.0. 2\bin if you are installing "JDK 14.0. 2". This is the location where the Java compiler ('java.exe') was installed in your file system.

Why is Java compiler not working?

It means that javac.exe executable file, which exists in bin directory of JDK installation folder is not added to PATH environment variable. You need to add JAVA_HOME/bin folder in your machine's PATH to solve this error. You cannot compile and run Java program until your add Java into your system's PATH variable.

Is javac a Java compiler?

Java is considered as both interpreted and compiled. It uses a Java compiler (javac) and JVM ( which is actually a software-based interpreter) to execute a Java application on a machine completely.

Is javac exe a compiler?

DESCRIPTION. The javac tool reads class and interface definitions, written in the Java programming language, and compiles them into bytecode class files.

Why can't I find a javac compiler in Eclipse?

Therefore the hint from ant : "Unable to find a javac compiler;..." When working with Eclipse the default setting points to your JRE installation. Window > Preferences > Java > Installed JREs and change the settings from JRE to JDK. Show activity on this post. I had the same problem.

How to fix javac not found in JRE?

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.

Why can't I find tools in Java_home?

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. Show activity on this post. In windows, go to computer properties, advanced system settings, advanced, environment variables


1 Answers

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
like image 53
Arunsg Avatar answered Oct 07 '22 03:10

Arunsg