Ant 公然无视 JAVA_HOME 环境变量 [英] Ant flagrantly ignoring JAVA_HOME environment variable

查看:36
本文介绍了Ant 公然无视 JAVA_HOME 环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚选择了最新版本的 Android SDK 并开始尝试使用它.与几乎所有提出这个问题的人不同,我正在运行 Linux,即 Linux Mint 13.我目前正在尝试使用 ant 编译一个 Hello World 程序,通过

I just picked up the latest version of the Android SDK and started trying to use it. Unlike almost everyone else coming up with this problem, I'm running Linux, namely Linux Mint 13. I'm currently trying to compile a Hello World program using ant, installed via

sudo apt-get install ant

并在项目文件夹中运行:

and ran in the project folder:

ant debug

然而,它完全无法编译,最终吐出与设置JAVA_HOME有关的错误.我相应地修改了我的 ~/.bashrc 文件并重新启动,但我仍然收到错误:

However, it fails utterly to compile, eventually spitting out an error to do with setting JAVA_HOME. I amended my ~/.bashrc file accordingly and restarted, but I still get the error:

Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-7-openjdk-amd64/jre"

Total time: 1 second
jamie@jamie-ThinkPad-E525 ~/Downloads/adt-bundle-linux/sdk/tools/projects/new $ echo $JAVA_HOME
/usr/java/jdk1.7.0_05/

正如你所看到的,它正从牙齿里钻出来.

As you can see, it's lying through its teeth.

我发现很多关于这个问题的参考资料,但大多数人要么错误地设置了他们的 JAVA_HOME,要么将它设置为 JRE.很明显,我没有做过.

I've found lots of references to this problem, but most people have either set their JAVA_HOME incorrectly, or set it to the JRE. Clearly, I have done neither.

我还修改了我的项目文件夹的 ant.properties 文件,添加了一行

I also amended my project folder's ant.properties file, adding the line

java.home=/usr/java/jdk1.7.0_05/

无济于事.

有没有其他人遇到/解决过这个问题,或者有什么想法?谢谢.

Has anyone else experienced/solved this problem, or got any ideas? Thanks.

推荐答案

很可能 ant 说的是实话,并且环境变量没有设置.可能性是:

The chances are that ant is telling the truth and that the environment variable is not set. The chances are that:

  • 您在.bashrc"文件中放入了错误的语句,或者
  • 您没有正确地重新启动.

无论如何,您可以通过在 shell 中运行 export 来验证这一点,然后再运行 ant 命令......并查看 JAVA_HOME变量被列出.

Anyway, you can verify this by running export in the shell before to run the ant command ... and looking to see if the JAVA_HOME variable is listed.

提示:

1) 这是错误的:

JAVA_HOME=/usr/java/jdk1.7.0_05/

这只会创建一个本地 shell 变量,并且本地 shell 变量不会传递给子进程(如 ant 命令).应该是:

That only creates a local shell variable, and local shell variables are NOT passed to child process (like the ant command). It should be:

export JAVA_HOME=/usr/java/jdk1.7.0_05/

2) 尝试运行这个:

export JAVA_HOME=/usr/java/jdk1.7.0_05/
ant

3) 将 java.home=/usr/java/jdk1.7.0_05/ 添加到 ant.properties 不会有帮助.Ant 需要环境变量中的设置.

3) Adding java.home=/usr/java/jdk1.7.0_05/ to ant.properties won't help. Ant expects the setting in an environment variable.

4) 计算机程序不会说谎.他们说实话,他们看到了.或者更准确地说,除非代理人有意图,否则撒谎和说实话的整个概念都是毫无意义的.但关键是,如果您开始怀疑计算机程序试图欺骗您,您将很难调试.

4) Computer programs don't lie. They tell the truth as they see it. Or to be more accurate, the whole notion of lying and telling the truth is meaningless unless the agent is capable of intention. But the point is that if you start to suspect computer programs of trying to deceive you, you are going to have a hard time debugging things.

(好吧,你在开玩笑.但许多面临故障排除问题的人都采用了类似的无效方法;例如,假设每个棘手的 Java 问题都是编译器/语言/运行时损坏的证据.IMO - 它是值得提醒的是,这种想法可能非常无益......)

这篇关于Ant 公然无视 JAVA_HOME 环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆