开发者

Ant and Eclipse

开发者 https://www.devze.com 2023-04-11 10:25 出处:网络
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 boo开发者_Python

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 boo开发者_Python百科k 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.


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).

Ant needs to find the JDK first in the PATH.


Install the JDK, latest version, and check the environment variable JAVA_HOME.
If it is not found, create it and set it to C:\Program Files\Java\jdk1.7.0 ...


tools.jar contains the java compiler, and only comes with the Java Development Kit (JDK). Your error message point to the Java Runtime (JRE).

From Eclipse, you set that from Window/Preferences/Java/Installed JREs. This is equivalent to, and will override, the alternative way of setting it via Windows environment variables.


I tried installing the JDK - jdk1.7.0_09 and did whatever was needful in the Environment Variables section but i still was getting this error

"Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre7\li b\tools.jar Buildfile: build.xml does not exist! Build failed"

Tools.jar file did not really exists in this path, instead i found it in C:\Program Files\Java\jdk1.7.0_09\lib

so i simply copied this tools.jar file and placed it under C:\Program Files\Java\jre7\li b\

and it worked - (not sure if that was the right way)

Now when i typed in the cmd prompt "ant" it gave me the below error :

Buildfile: build.xml does not exist! Build failed

On investigating it further i found that if you get the above error it means that ant is installed successfully

http://ant.apache.org/manual/install.html#getBinary - Check Installation


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.


please search and change this line in all files.:

<equals arg1="1.5" arg2="${ant.java.version}"/>

for

<equals arg1="1.5" arg2="1.5"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号