Linux Ant 找不到 javac,在 Ubuntu 上不会设置 JAVA_HOME
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5736641/
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 unable to find javac, JAVA_HOME won't set on Ubuntu
提问by lollercoaster
I have an Android Project called Hello on my Ubuntu 10.04 i386 Server (headless). It contains all things an Android project folder should have. I first build the project in bash while in the Project folder using this synax:
我的 Ubuntu 10.04 i386 服务器(无头)上有一个名为 Hello 的 Android 项目。它包含了一个 Android 项目文件夹应该有的所有东西。我首先在项目文件夹中使用以下 Synax 在 bash 中构建项目:
./android create project --target 5 --name HelloCompile --path ../../Projects/Hello --activity HelloActivity --package com.code.Hello
then I try to build the .apk with ant like so:
然后我尝试使用 ant 构建 .apk,如下所示:
ant debug
I get this error:
我收到此错误:
BUILD FAILED
/home/myusername/www/sdk/tools/ant/main_rules.xml:384: 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 "/usr/lib/jvm/java-6-openjdk/jre"
which is very confusing to me because just before I run ant debug
I run:
这让我很困惑,因为就在我跑步之前,ant debug
我跑了:
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
which I know works because printenv
in bash shell returns:
我知道这是有效的,因为printenv
在 bash shell 中返回:
JAVA_HOME=/usr/lib/jvm/java-6-openjdk
to compound this, adding this line to my /etc/environment file
为了复合这一点,将此行添加到我的 /etc/environment 文件中
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
does not fix the problem either - I get the same error. Nothing I do changes the fact Ubunut still thinks /usr/lib/jvm/java-6-openjdk/jre
is the JAVA_HOME. What is going wrong? I've been at this for too many hours.
也不能解决问题 - 我得到了同样的错误。我所做的一切都没有改变 Ubunut 仍然认为/usr/lib/jvm/java-6-openjdk/jre
是 JAVA_HOME的事实。出了什么问题?我已经在这里呆了太多小时了。
采纳答案by Brian Roach
Did you install the JDK?
你安装JDK了吗?
When you install Ubuntu only the JRE is installed as part of the default packages. Unfortunately Ubuntu's package management names the directory as if the JRE were installed along with the JDK. The directory is named java-6-openjdk
even though the JDK is not be present.
安装 Ubuntu 时,仅将 JRE 作为默认包的一部分安装。不幸的是,Ubuntu 的包管理将目录命名为好像 JRE 与 JDK 一起安装一样。java-6-openjdk
即使不存在 JDK,也会命名该目录。
Do the following:
请执行下列操作:
sudo apt-get install openjdk-6-jdk
It will install the JDK in that same directory.
它将在同一目录中安装 JDK。
回答by Edwin Buck
--- Updated after noticing a small item in your output ---
--- 在您的输出中注意到一个小项目后更新 ---
You have your JAVA_HOME
set to the correct location for a Java Runtime Environment, which unsuprisingly will allow you to run Java programs, but not develop them.
您已将Java 运行时环境JAVA_HOME
设置为正确的位置,这无疑将允许您运行 Java 程序,但不能开发它们。
Shorten your JAVA_HOME
to /usr/lib/jvm/java-6-openjdk
(note the removal of the trailing jre
). After that your Ant wrappers / compiler detection code won't get confused, as it will be pointing to the home of your Java Development Environmentinstead of the embedded, related Java Runtime Environment.
缩短JAVA_HOME
到/usr/lib/jvm/java-6-openjdk
(注意删除尾随jre
)。之后,您的 Ant 包装器/编译器检测代码将不会被混淆,因为它将指向您的Java 开发环境的主页,而不是嵌入的、相关的Java 运行时环境。
The embedded Java Runtime Environmentis provided to make sure you can test against just the core (compiler tools not included) Java offerings.
提供嵌入式Java 运行时环境以确保您可以仅针对核心(不包括编译器工具)Java 产品进行测试。
--- Original post follows ---
--- 原帖如下---
Finding the command javac
has little to do with JAVA_HOME
beyond that javac
is typically found in a subdirectory under JAVA_HOME
查找命令javac
有一点做与JAVA_HOME
那超出javac
一般是在子目录下找到JAVA_HOME
What you need to do is to modify your PATH
environmental variable to include the directory where the Java executables are located. Typically this is done like so
您需要做的是修改您的PATH
环境变量以包含 Java 可执行文件所在的目录。通常这是这样做的
PATH=${PATH}:${JAVA_HOME}/bin
export PATH
but it might be done slightly differently depending on your setup. If you do
但根据您的设置,它可能会略有不同。如果你这样做
ls ${JAVA_HOME}/bin
and you see a javac executable, then the above modification of the path variable will work without any need to change it.
并且您看到一个 javac 可执行文件,那么上面对路径变量的修改将起作用,无需更改它。
回答by garec
As Edwin Buck stated, check your $PATH for softlinks to /etc/alternatives/java in the /usr/bin/ directory. They are being read before your appended JAVA_HOME variable.
正如 Edwin Buck 所说,检查您的 $PATH 以获取 /usr/bin/ 目录中 /etc/alternatives/java 的软链接。它们在您附加的 JAVA_HOME 变量之前被读取。
That was my problem:
那是我的问题:
ls -al /usr/bin/j*
lrwxrwxrwx 1 root root 22 2012-05-07 13:26 /usr/bin/java -> /etc/alternatives/java
lrwxrwxrwx 1 root root 25 2011-05-12 19:45 /usr/bin/java_vm -> /etc/alternatives/java_vm
lrwxrwxrwx 1 root root 24 2011-05-01 05:22 /usr/bin/javaws -> /etc/alternatives/javaws
lrwxrwxrwx 1 root root 26 2011-05-12 19:45 /usr/bin/jcontrol -> /etc/alternatives/jcontrol
lrwxrwxrwx 1 root root 23 2011-04-26 02:24 /usr/bin/jexec -> /etc/alternatives/jexec
回答by brandoncurtis
Changing JAVA_HOME and PATH are insufficient.
改变 JAVA_HOME 和 PATH 是不够的。
After installing the Java JDK version that you want (Java DEVELOPMENT Kit, not just Java Runtime Environment JRE), change your preferred version with sudo update-alternatives --config java
. If you're on Ubuntu, you probably have 1.6 and 1.7 installed, and 1.8 is available in the PPAs (though I can't find a PPA of 1.8 that's not old).
安装所需的 Java JDK 版本(Java DEVELOPMENT Kit,而不仅仅是 Java Runtime Environment JRE)后,使用sudo update-alternatives --config java
. 如果您使用的是 Ubuntu,则您可能安装了 1.6 和 1.7,并且 1.8 在 PPA 中可用(尽管我找不到不旧的 1.8 PPA)。