Reputation: 3341
I want to build my project in Eclipse using Ant. When running the XML script, I get the following error:
BUILD FAILED
C:\thesis\100GreatP\eclipse_ws\test\build.xml:82: 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"
It says it fails to search for javac compiler and also says it is currently set to C:\Program Files\Java\jre7
, but that is not true. In environment variables, I have defined JAVA_HOME=C:\Program Files\Java\jdk1.7.0_21\bin;
and PATH=C:\Program Files\Java\jdk1.7.0_21\bin;
as well. My CLASSPATH
variable is defined like this - CLASSPATH=C:\Program Files\Java\jre7\lib;
. Any ideas what else can cause this kind of error? Thanks.
Upvotes: 0
Views: 3771
Reputation: 436
You can see which jdk your eclipse ant uses if you go to your eclipse preferences: Window->Preferences->Ant->Runtime->Classpath->Global Entries.
Check in the "Global Entries" the path to tools.jar. If you want to use another javac simply point to another tools.jar using the "Add External Jar" option.
The tools.jar can usually be found in any jdk under the /lib directory.
The first tools.jar defined in order of appearance will be used by your eclipse ant.
Upvotes: 1
Reputation: 975
I got the same error in two different versions of Eclipse.
I ran into this using Eclipse/Kepler. Initially I found that I hadn't installed a JDK; I reasoned that Eclipse must have a compiler so I should be able to do this without a JDK.
Sure enough - this Eclipse Wiki FAQ directed me to add the following to my Ant build file:
<property name="build.compiler"
value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
I got complaints about uses of Generics, so I found I had to add two more lines - this is what finally worked:
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<property name="ant.build.javac.source" value="1.6"/>
<property name="ant.build.javac.target" value="1.6"/>
The solution above didn't work for me in Eclipse Galileo. Instead I did the following to roll out MichalB's solution (and it worked):
bin
folder - in my case, C:\Program Files (x86)\Java\jdk1.6.0_16
.This PC
(I have Win8.1), picking Properties
, clicking on Advanced
and setting the System
environment variable JAVA_HOME to that value.Upvotes: 0
Reputation: 2013
Have you checked what ant -diagnostics
tells you about your JAVA_HOME
?
Probably your JAVA_HOME
is incorrect too; it shouldn't be C:\Program Files\Java\jdk1.7.0_21\bin
but better be C:\Program Files\Java\jdk1.7.0_21
Upvotes: 2