eclipse 蚂蚁和日食
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7697044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ant and Eclipse
提问by Aly
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=XJmndRfb1TUand i'm getting this error:
嗨,我是一名初级 Java 程序员,最近我开始阅读 Thinking in Java 4th edition 以巩固我在阅读 Head first Java 后的 Java 知识。问题是这本书有它自己的图书馆,我似乎无法做到即使在我完成了网站指南上所说的所有内容之后,仍然可以在 Eclipse 中工作。我使用此视频指南http://www.youtube.com/watch?v=XJmndRfb1TU正确安装了 ant,但出现此错误:
"Unable to locate tools.jar.Expected to find it in C:\Program files\Java\jre7\lib\tools.jar Buildfile:C:\TIJ4\code\build.xml
“无法找到tools.jar。预计在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
构建失败 C:\TIJ4\code\build.xml:59:J2SE5 需要
Total time:0 seconds
总时间:0秒
I tried reinstaling JDK witch was suggested on a forum but it still dident work so I don't really know what to do.
我尝试在论坛上建议重新安装 JDK 女巫,但它仍然有效,所以我真的不知道该怎么做。
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.
谁能告诉我如何解决这个问题?此外,更重要的是,如果不安装 Ant,单独使用 Eclipse 是否可以完成(我只使用 Eclipse 进行代码编写和编译,所以我对它不是很熟悉)谢谢你。
回答by mhaller
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.
您使用的是 JRE 而不是 JDK。安装 JDK 并将您的 PATH 和 JAVA_HOME 变量指向 JDK 主目录,而不是 JRE 主目录。
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.
我看到 Ant 正在使用 JRE 中的 Java Home,例如C:\Program files\Java\jre7\
但它应该是C:\Program files\Java\jdk1.7.0\
或类似的。
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).
检查系统的环境变量(例如同时按Windows键和Pause,然后选择扩展设置>环境变量。检查JAVA_HOME是否设置为JDK安装路径,并且在PATH变量中,JDK的文件夹在JRE(或使用 JDK 中的路径完全删除/替换 JRE 路径)。
Ant needs to find the JDK first in the PATH.
Ant 需要先在PATH 中找到JDK。
回答by jbenxtcl
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
...
安装最新版本的JDK,并检查环境变量JAVA_HOME
。
如果找不到,请创建它并将其设置为C:\Program Files\Java\jdk1.7.0
...
回答by soru
tools.jar contains the java compiler, and only comes with the Java Development Kit (JDK). Your error message point to the Java Runtime (JRE).
tools.jar 包含 java 编译器,仅随 Java Development Kit (JDK) 提供。您的错误消息指向 Java 运行时 (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.
在 Eclipse 中,您可以从 Window/Preferences/Java/Installed JREs 进行设置。这等效于并将覆盖通过 Windows 环境变量设置它的替代方法。
回答by unicus
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
我尝试安装 JDK - jdk1.7.0_09 并在环境变量部分做了任何需要的事情,但我仍然收到这个错误
"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。希望在C:\Program Files\Java\jre7\li b\tools.jar 中找到它构建文件:build.xml 不存在!构建失败”
Tools.jar file did not really exists in this path, instead i found it in C:\Program Files\Java\jdk1.7.0_09\lib
Tools.jar 文件在此路径中并不真正存在,而是我在 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\
所以我简单地复制了这个 tools.jar 文件并将它放在 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 :
现在,当我在 cmd 提示符“ant”中输入时,它给了我以下错误:
Buildfile: build.xml does not exist! Build failed
构建文件:build.xml 不存在!构建失败
On investigating it further i found that if you get the above error it means that ant is installed successfully
在进一步调查时,我发现如果出现上述错误,则表示 ant 已成功安装
http://ant.apache.org/manual/install.html#getBinary- Check Installation
回答by Симон Разбираш
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%
ivantrox86 说的是对的,但是你需要在所有的 build.xml 文件中都这样做,而且大概有 20 个。所以转到 c:\tij4\code 目录中的每个文件夹并找到每个 build.xml 文件,并将第二个参数 (arg2) 更改为 1.5,而不是默认值 (${ant.java.version}) . 工作 100%
回答by Terry Horner
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.
如果JAVA_HOME
设置不正确,ant 可能会发生这种情况- 它似乎试图猜测该值应该是什么并提供 jre7 地址。在我的情况下,设置 JAVA_HOME
来C:\Progra~1\Java\jdk1.7.0_45
解决问题。当然地址会因你的jdk安装位置而异。
回答by ivantrox86
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"/>