简体   繁体   中英

setting JAVA_HOME in windows 7

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.

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\\

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

Then in your path variable add %JAVA_HOME%\\bin

JAVA_HOMEC:\\mypath\\Java\\jdk1.7.0_17\\并将C:\\mypath\\Java\\jdk1.7.0_17\\binPATH

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM