21

I cannot run my Ant build.xml since I updated to java 1.7.0_52 (or there about). I have been running it for years through Eclipse locally on my Windows 7 laptop - but with this latest jave jdk update somethings different (?).

BUILD FAILED
C:\workspace\WaterAspectsModel3\build.xml:329: 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 "D:\Morten\Java\jdk1.7.0_52"

This is my jdk! So JAVA_HOME is pointing to a jdk (as is also clear from the error message). I have my JAVA_HOME with bin folder in my path as always. I've configured Eclipse - external tools configuration - with a JRE pointing to the same D:\Morten\Java\jdk1.7.0_52 (through "Separate JRE" setting). And I've tried a number of other configurations - all without luck.

I've been reading the tonnes of answers on lists here and other places and think I've tried all suggestions. Most seem to be cases where JAVA_HOME actually points to a jre and just needs to be corrected to jdk or there's a ";" in the path or something like that. None of these seem to apply in my case.

Any suggestions?

Undo
  • 25,519
  • 37
  • 106
  • 129
Morten Grum
  • 962
  • 1
  • 10
  • 25

6 Answers6

40

I was having the same message when running ANT through Eclipse.

What worked for me:

  1. In Eclipse, access the menu: "Window -> Preferences";
  2. Access "Ant -> Runtime", at the tree;
  3. Access the Classpath tab;
  4. Expand the "Global Entries" item;
  5. Inside Global Entries, the path to tools.jar was wrong. It was pointing to an older version of Java;
  6. I removed the wrong entry and added the correct one with "Add External Jars" button. It worked.

enter image description here

viniciussss
  • 4,404
  • 2
  • 25
  • 42
11

The solution "Had to copy C:\Program Files\Java\jdk1.6.0_10\lib\tools.jar to C:\Program Files\Java\jre6\lib\ext" from here was great helpful and worked for me.

Bose
  • 243
  • 3
  • 11
8

The real message is that Ant can't find com.sun.tools.javac.Main.

Which, together with the fact that the latest "Sun" (Oracle) JDK is 1.7.0_13 (or maybe _14, but definitely not the "_52" that your install dir indicates), makes me think that you're not using a distribution that Ant recognizes. You can verify this by running jar tvf $JAVA_HOME/lib/tools.jar, and looking for that class.

The Ant Manual talks about ways to work with different compilers. Since I've only used "Sun" compilers, I'm afraid that I can't give you any pointers.


Edit: you could also try setting fork="yes" in your build file. This should run the compiler executable rather than trying to invoke the compiler class.

parsifal
  • 529
  • 2
  • 4
  • 4
    It's much more likely that the JAVA_HOME variable is pointing at a JRE instead of a JDK. There are two distributions of Java, only the "Java Development Kit" contains the **javac** command and other useful binaries used by developers – Mark O'Connor Feb 26 '13 at 20:50
  • 1
    @MarkO'Connor - possibly, although the OP claims to have checked that multiple times, so I see no reason to argue otherwise, The presence (or absence) of `tools.jar` would be strong evidence either way. The thing that makes me think it might be something else is the version number of the installation directory. – parsifal Feb 26 '13 at 20:59
  • THANKS parsifal! I'm not there yet but the "jar tvf tools.jar" clearly indicated that this was a tools.jar from a complete different project. Just uninstalling and re-installing my jdk. – Morten Grum Feb 26 '13 at 20:59
  • @MortenGrum - unless you have a good reason to do otherwise, I recommend downloading the Oracle distribution: http://www.oracle.com/technetwork/java/javase/downloads/index.html – parsifal Feb 26 '13 at 21:06
  • 1
    SOLVED! Re-installing the jdk (to the one you recommended) did the trick! I seem to remember some time back getting a jdk without tools.jar and then some fool (undoubtedly me) seems to have picked the nearest tools.jar file and copied it in. Not too smart - and no wander I didn't find much help the the existing posts. THANKS for leading me to it! – Morten Grum Feb 26 '13 at 21:45
  • Eclipse > WaterAspectsModel3 > Right-click > Properties > Java Build Path > Libraries > Add External Jar > ${someJDKDistributionOnYourDrive}/lib/tools.jar worked for me. – user77115 May 30 '14 at 17:58
0

Try adding JAVA_HOME\bin to your env PATH .

0

Add JAVA_HOME to Eclipse-Preferences-Java-Build Path-Classpath Variables.

superuser
  • 768
  • 7
  • 9
0

Sorry for the unearthing,

I had the same problem, my solution doesn't need any modification in environment variables, and works for a recent JDK where the tools.jar can't be found.

Just go in the small down-arrow next to the ant run button Then click "Configure external tools" Then in JRE tab Select a JDK installed on your computer, not a JRE, no problems if the selected JDK is not the same JDK/JRE as in your project.

It should be work now.

ROMAINPC
  • 81
  • 6