-1

I am getting the following error when I try to run an ant buildfile in eclipse:

BUILD FAILED
C:\mypath\myapp\BuildWar.xml:16: 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"  

I located the jdk at C:\mypath\Java\jdk1.7.0_17\bin\javac.exe

I used the methods in this blog entry to create a system environmental variable in windows 7 called JAVA_HOME and mapped to C:\mypath\Java\jdk1.7.0_17\bin\javac.exe . When the error persisted, I restarted the computer, tried again, and got the same error. I then changed the mapping of JAVA_HOME to C:\mypath\Java\jdk1.7.0_17\bin\ and still got the same error.

Can anyone show me how to get past this error, so that I can run my ant build file in eclipse?


EDIT:

I am getting the same exact error message again today when I try to run the ant buildfile, even though JAVA_HOME is set as per the answers below, and even though the path variable now includes %JAVA_HOME%\bin . I have checked the values of these environmental variables in the windows control panel section for setting environmental variables, even though the eclipse console gives the above error message saying JAVA_HOME is set to a jre. Does anyone have any suggestions about how to fix this recurring problem?


SECOND EDIT:

Changing the Java Home in eclipse fixed this problem. The eclipse Java Home is separate from the windows Java Home.

CodeMed
  • 9,527
  • 70
  • 212
  • 364
  • 3
    Map JAVA_HOME to C:\mypath\Java\jdk1.7.0_17 only. Hope that fixes your problem. – Yogendra Singh Aug 15 '13 at 21:17
  • @YogendraSingh +1 for helping. My program runs now. Thanks. – CodeMed Aug 15 '13 at 21:39
  • @YogendraSingh I am getting the same exact error message again today when I try to run the ant buildfile, even though JAVA_HOME is set as you instructed, and even though the path variable now includes %JAVA_HOME%\bin . Do you have any suggestions? – CodeMed Aug 19 '13 at 19:01
  • Can you please try running "java -version" from your command prompt and check if it is printing the right version? – Yogendra Singh Aug 19 '13 at 19:32
  • @YogendraSingh Thank you. The result of running java -version is java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b16) Java Hotspot(TM) 64-bit Server VM (build 23.25-b01, mixed mode). Any more suggestions? – CodeMed Aug 19 '13 at 19:41
  • As next steps, I would suggest to add some "echo" statements to print "Path" and "Java_Home" value just before the failure statement. I am just thinking, if there is any override with in the build file. – Yogendra Singh Aug 19 '13 at 20:00
  • @YogendraSingh Can you suggest a way to do something within the ant buildfile itself? I would prefer not to add the complexity of writing a command line program. My command line skills are beginner level, and so are my ant skills. I am most comfortable writing code inside eclipse, and ant is a new part of eclipse for me. – CodeMed Aug 19 '13 at 20:07
  • You may want to use "echo (http://ant.apache.org/manual/Tasks/echo.html)" to print the values. Also you may want to run the build with -v option to receive the detailed error message. – Yogendra Singh Aug 20 '13 at 03:11
  • @YogendraSingh Thank you. It works now. I put an explanation of the fix in the second edit to my original post above. – CodeMed Aug 20 '13 at 19:20

4 Answers4

8

The JDK is the whole installation bundle, not just the javac executable.

Your JAVA_HOME environment variable should point to the top of your JDK installation, in your case - this means:

C:\mypath\Java\jdk1.7.0_17\

Penumbra
  • 158
  • 1
  • 10
  • I made an edit to my original posting above describing how the error is back again, even though windows tells me that the environmental variables are still set properly. Any suggestions? – CodeMed Aug 19 '13 at 19:08
2

Set JAVA_HOME to C:\mypath\Java\jdk1.7.0_17\

Then in your path variable add %JAVA_HOME%\bin

Java Devil
  • 10,629
  • 7
  • 33
  • 48
  • +1 for trying to help. And credit for the answer, because this is the actual syntax that I used. My program runs now. Thanks. – CodeMed Aug 15 '13 at 21:36
  • I made an edit to my original posting above describing how the error is back again, even though windows tells me that the environmental variables are still set properly. Any suggestions? – CodeMed Aug 19 '13 at 19:08
  • What happens if you open a command prompt an type `ant -version` – Java Devil Aug 19 '13 at 20:48
  • Thank you. Oddly enough, the result is 'ant' is not recognized as an internal or external command, operable program, or batch file. Any further suggestions? – CodeMed Aug 19 '13 at 21:00
  • It may not be an Issue for running from eclipse but that suggests that `ANT_HOME` is not set. Check the [Ant Install Manual](http://ant.apache.org/manual/install.html) on how to do this. Another thing to check would be to make sure you don't have multiple Java Paths in your Path – Java Devil Aug 19 '13 at 21:06
  • Thank you. I checked, and there is only the one java path in my Path. ANT_HOME is not listed in the environmental variables, but the ant buildfile has run from within eclipse in the past. I can try to set ANT_HOME when I have more time later. Do you have any other ideas? – CodeMed Aug 19 '13 at 21:28
  • 1
    Check out [this post](http://stackoverflow.com/questions/1288343/how-to-change-java-home-for-eclipse-ant) also to check your java home for eclipse, appears it is not the same as the windows java home. – Java Devil Aug 19 '13 at 21:48
  • Thank you. Changing the Java Path within eclipse was what fixed the problem. +1 for the silver bullet. – CodeMed Aug 20 '13 at 19:19
1

Set JAVA_HOME to C:\mypath\Java\jdk1.7.0_17\ and add C:\mypath\Java\jdk1.7.0_17\bin to PATH.

ps-aux
  • 11,627
  • 25
  • 81
  • 128
  • I made an edit to my original posting above describing how the error is back again, even though windows tells me that the environmental variables are still set properly. Any suggestions? – CodeMed Aug 19 '13 at 19:09
0
  1. Right click on My computer/ThisPC and click on properties option.
  2. Click on Advanced system settings.
  3. Click on Environment Variables.
  4. Add JAVA_HOME (to java home path) Example: C:\Program Files\Java\jdk1.8.0_111
  5. Add PATH(Path to Java bin directory) Example: C:\Program Files\Java\jdk1.8.0_111\bin
  6. Click on Apply and OK.

Visit this blog to see all steps with image: https://javatutorialdetails.blogspot.in/2017/10/how-java-program-work-step-by-step-in.html

M J
  • 11
  • 1