Go to Environment variable and add
JAVA_HOME=C:\Program Files (x86)\Java\jdk1.6.0_37
till jdk path (exclude bin folder)
now set JAVA_HOME into path as
This will set java path to all the applications which are using java.
For ANT use,
ANT_HOME=C:\Program Files (x86)\apache-ant-1.8.2\bin;
and include ANT_HOME into PATH, so path will look like
Set environment variables
This is the part that I always forget. Because you’re installing Ant by hand, you also need to deal with setting environment variables by hand.
For Windows XP: To set environment variables on Windows XP, right click on My Computer and select Properties. Then go to the Advanced tab and click the Environment Variables button at the bottom.
For Windows 7: To set environment variables on Windows 7, right click on Computer and select Properties. Click on Advanced System Settings and click the Environment Variables button at the bottom.
The dialog for both Windows XP and Windows 7 is the same. Make sure you’re only working on system variables and not user variables.
The only environment variable that you absolutely need is JAVA_HOME, which tells Ant the location of your JRE. If you’ve installed the JDK, this is likely
c:\Program Files\Java\jdk1.x.x\jre on Windows XP and
c:\Program Files(x86)\Java\jdk1.x.x\jre on Windows 7. You’ll note that both have spaces in their paths, which causes a problem. You need to use the mangled name instead of the complete name. So for Windows XP, use
C:\Progra~1\Java\jdk1.x.x\jre and for Windows 7, use
C:\Progra~2\Java\jdk1.6.0_26\jre if it’s installed in the Program Files(x86) folder (otherwise use the same as Windows XP).
That alone is enough to get Ant to work, but for convenience, it’s a good idea to add the Ant binary path to the PATH variable. This variable is a semicolon-delimited list of directories to search for executables. To be able to run ant in any directory, Windows needs to know both the location for the ant binary and for the java binary. You’ll need to add both of these to the end of the PATH variable. For Windows XP, you’ll likely add something like this:
For Windows 7, it will look something like this:
Once you’ve done that and applied the changes, you’ll need to open a new command prompt to see if the variables are set properly. You should be able to simply run ant and see something like this:
Buildfile: build.xml does not exist! Build failed
If you are using Eclipse, try the following:
- Right click on the ant build file, then choose "Properties".
- Click on the "Run/Debug Settings", then click on the launch configuration file. You should be able to edit it then.
- After you click "Edit", you should see a new window with a "Properties" tab which will show you a list of Ant build properties. There is a "java.home" property in the list. Make sure it refers to the correct path.
Spent a few hours facing this issue this morning. I am likely to be the least technical person on these forums. Like the requester, I endured every reminder to set %JAVA_HOME%, biting my tongue each time I saw this non luminary advice. Finally I pondered whether my laptop's JRE was versions ahead of my JDK (as JREs are regularly updated automatically) and I installed the latest JDK. The difference was minor, emanating from a matter of weeks of different versions. I started with this error on jdk v 1.0865. The JRE was 1.0866. After installation, I had jdk v1.0874 and the equivalent JRE. At that point, I directed the Eclipse JRE to focus on my JDK and all was well. My println of java.home even reflected the correct JRE.
So much feedback repeated the wrong responses. I would strongly request that people read the feedback from others to avoid useless redundancy. Take care all, SG
Also be sure to set your
JAVA_HOME environment variable. In fact, I usually set the
JAVA_HOME, then prepend the string "
%JAVA_HOME%\bin" to the system's
PATH environment variable so that if Java ever gets upgraded or changed, only the
JAVA_HOME variable will need to be changed.
And make sure that you close any command prompt windows or open applications that may read your environment variables, as changes to environment variables are normally not noticed until an application is re-launched.
Simply, to enforce JAVA version to Ant in Eclipse:
Use RunAs option on Ant file then select External Tool Configuration in JRE tab define your JDK/JRE version you want to use.
Under Windows you need to follow:
Start -> Control Panel -> System -> Advanced -> Environment Variables.
... and you need to set JAVA_HOME (which is distinct from the PATH variable you mention) to reference the JDK home directory, not the bin sub-directory; e.g. "C:\program files\java\jdk".
For me, ant apparently refuses to listen to any configuration for eclipse default, project JDK, and the suggestion of "Ant Home Entries" just didn't have traction - there was nothing there referring to JDK.
However, this works:
Menu "Run" -> "External Tools" -> "External Tools Configuration". Goto the node "Ant build", choose the ant buildfile in question. Choose tab "JRE". Select e.g. "Run in same JRE as workspace", or whatever you want.
In Eclipse the Ant java.home variable is not based on the Windows JAVA_HOME environment variable. Instead it is set to the home directory of the project's JRE.
To change the default JRE (e.g. change it to a JDK) you can go to Windows->Preferences... and choose Java->Installed JREs.
To change just a single project's JRE you can go to Project->Properties and choose Java Build Path and choose the Libraries tab. Find the JRE System Library and click it, then choose Edit and choose the JRE (or JDK) that you want.
If that doesn't work then when running the build file you can choose Run as->Ant Build... and click the JRE tab, choose separate JRE and specify the JRE you want there.
- How to change font size in Eclipse for Java text editors?
- How do I change colors for the Java Docs Hover Over in Eclipse
- How to generate Ant and Maven build files for an Eclipse Java project?
- How to turn off the Eclipse code formatter for certain sections of Java code?
- How to change an Eclipse default project into a Java project
- How to upgrade Eclipse for Java EE Developers?
- How to change JDK version for an Eclipse project
- How to simultaneously run all JUnit tests for a Eclipse Java project without Maven?
- How can I change font size in Eclipse for ALL text editors?
- How to add shortcut keys for java code in eclipse
- How to create the pom.xml for a Java project with Eclipse
- How do I Install JBoss AS / WildFly Server in Eclipse for Java EE
- How to debug Java code when using ANT script in Eclipse
- How to change default JRE for all Eclipse workspaces?
- How to convert an Eclipse Android project to use Ant for build?
- How to filter call stack in Eclipse debug view for Java
- How to change the background color for changed files in eclipse project explorer?
- How can I get Eclipse to insert tabs instead of spaces for Java content assist?
- Eclipse dark theme for windows: how to change the color of scroll bars and title bars to dark?
- How can I upgrade from Eclipse Java SE version to Eclipse for Java EE via Eclipse?
- How can I add an Eclipse Quick Fix for a custom Java marker?
- How to use Eclipse for both Java and PHP?
- How to stop Eclipse from moving cursor for closing java parenthesis?
- How can I enable the Task List in Eclipse for a Java Project?
- How to use different line wrapping for strings and other items in Eclipse for Java
- How to change the Control+Space autocomplete shortcut keys in Eclipse for Android
- How to configure opencv in Eclipse for Java developers with plugin CDT?
- How do I set the Java Doc for google drive api for android in Eclipse
- Ant Build Error in Eclipse IDE for Java
- How to change Eclipse indentation style for automatically generated code?
More Query from same tag
- Lambda and cast intersection type (Eclipse compiler bug)
- android get video thumbnail PATH, not Bitmap
- Importing zk essential chapter 10 into Eclipse Fails while installing JPA
- Eclipse -> MySQL connection fail
- How to use mailed .class files in eclipse
- Eclipse/Java can't start any project
- Cucumber .feature file is not getting linked to stepDefinition.java in Eclipse
- Eclipse IDE not working
- Problem with Phonegap eclipse plugin installation
- I can't find the debug.keystore file
- Export Libgdx Project to Android
- How to force cppstyle to use c and h files?
- Run android 4.2.2 build target application in android 4.4.2
- Scala running issue on eclipse
- Exception in thread "main" java.lang.NullPointerException, at stensakspapir.main(stensakspapir.java:34)
- Mass import of keymappings from Eclipse to Android Studio
- Where do I apply my updated github personal access token (PAT) in eclipse?
- How to import a project which you just deleted in eclipse
- Google cloud messaging endpoint register fails locally
- Eclipse Luna 1.7 to 1.8 errors
- how to get neo4j Graph database in GWT with eclipse running
- Unable to Execute Test Case through TestNG
- Eclipse switches @ and "
- Inspecting contents of std::vector in Eclipse CDT debugger
- Could not get JDBC Connection; nested exception is java.sql.SQLException - junit eclipse
- How can I get my Properties tab back in Eclipse?
- When I commit a project an extra project dir is created
- JavaDoc Tags in Eclipse
- Eclipse M2E changing org.eclipse.wst.common.component
- Proper way to use 3rd party .so files in android