Hi I am a beginner java programmer and recently I've started reading Thinking in Java 4th edition to consolidate my knoledge of java after I read Head first Java.Problem is that this book has it's own library and I can't seem to make it work in eclipse even after I did everything it said on the website guide.I instaled ant acordinly with this video guide http://www.youtube.com/watch?v=XJmndRfb1TU and i'm getting this error:

"Unable to locate tools.jar.Expected to find it in C:\Program files\Java\jre7\lib\tools.jar
Buildfile:C:\TIJ4\code\build.xml

build:

BUILD FAILED
C:\TIJ4\code\build.xml:59:J2SE5 required

Total time:0 seconds

I tried reinstaling JDK witch was suggested on a forum but it still dident work so I don't really know what to do.

Can anyone tell me how can I solve this problem? Also, more importantly, can't this be done with Eclipse alone without installing Ant(I've only used eclipse for code writing and compiling so I'm not very familiar with it)Thant you.

7 Answers
7

You are using a JRE instead of a JDK. Install a JDK and point your PATH and JAVA_HOME variables to the JDK home, not to the JRE home.

I see that Ant is using the Java Home from the JRE, e.g. C:\Program files\Java\jre7\
But it should be C:\Program files\Java\jdk1.7.0\ or similar.

Check your system's environment variables (e.g. press Windows-Key and Pause together, then select Extended Settings > Environment Variables. Check that JAVA_HOME is set to the JDK installation path and that in the PATH variables, the folder of the JDK comes before the folder of the JRE (or remove/replace the JRE path altogether with the one from the JDK).

I have solved this error "Unable to locate tools.jar.Expected to find it in C:\Program files\Java\jre7\lib\tools.jar Buildfile:C:\TIJ4\code\build.xml now I'm geting only this any tips:BUILD FAILED C:\TIJ4\code\build.xml:59:J2SE5 required any tips on how I can solve this error 2?
–
AlyOct 8 '11 at 13:35

Please post line 50-60 of your build.xml. What ant task is being called there? Is it the <javac> ant task?
–
mhallerOct 9 '11 at 10:15

what ivantrox86 said is true, but you need to do it in all the build.xml files, and there are like 20 of them. so go to each and every folder in the c:\tij4\code directory and find every build.xml file, and change the second argument (arg2) to 1.5, instead of the default value (${ant.java.version}). works 100%

This can happen with ant if JAVA_HOME is set incorrectly - it seems to try to guess what the value should be and comes up with the jre7 address. In my case setting JAVA_HOME to C:\Progra~1\Java\jdk1.7.0_45 fixed the problem. Of course the address will vary depending on where your jdk is installed.