即使设置正确,Gradle 也会发现错误的 JAVA_HOME [英] Gradle finds wrong JAVA_HOME even though it's correctly set

查看:27
本文介绍了即使设置正确,Gradle 也会发现错误的 JAVA_HOME的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试运行 gradle 时,出现以下错误:

When trying to run gradle, I get the following error:

# gradle

ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/default-java

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

但是,当我检查 JAVA_HOME 变量时,我得到:

However, when I check the JAVA_HOME variable I get:

# echo $JAVA_HOME 
/usr/lib/jvm/java-7-oracle

我的 JAVA_HOME 是在 .bashrc 中定义的,我已经仔细检查过它是否被设置为源.

My JAVA_HOME is defined in .bashrc and I have double checked that it is set as the source.

运行 java -version 还确认 JAVA_HOME 设置正确并且在 PATH 上.

Running java -version also confirms that JAVA_HOME is set correctly and is on the PATH.

# java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

我还检查了 /usr/bin/java/etc/alternatives/java 的符号链接,后者又正确地链接到 /usr/lib/jvm/java-7-oracle/jre/bin/java

I have also checked that /usr/bin/java symlinks to /etc/alternatives/java which in turn correctly symlinks to /usr/lib/jvm/java-7-oracle/jre/bin/java

此外,我还检查了 .bash_profile/etc/profile 中没有重复的 JAVA_HOME 定义.

Additionally I've checked that there are no duplicate JAVA_HOME definitions in .bash_profile or /etc/profile.

所以我的问题是 Gradle 如何/为什么找到 /usr/lib/jvm/default-java,更重要的是我如何将它指向正确的目录?

So my question is how/why does Gradle find /usr/lib/jvm/default-java, and more importantly how do I point it to the correct directory?

其他需要 JDK 的程序运行良好,所以我认为这是 Gradle 问题.我也试过重新安装 Gradle,但没有任何区别.

Other programs which require the JDK work fine, so I think its a Gradle issue. I've also tried reinstalling Gradle which made no difference.

我正在运行 64 位 Xubuntu(基于 Ubuntu 13.10)

I'm running 64bit Xubuntu (Ubuntu 13.10 base)

推荐答案

结果是我从 Ubuntu 13.10 存储库下载的特定 Gradle 二进制文件本身试图导出 JAVA_HOME.感谢 Lucas 提出这个建议.

Turns out that the particular Gradle binary I downloaded from the Ubuntu 13.10 repository itself tries to export JAVA_HOME. Thanks to Lucas for suggesting this.

/usr/bin/gradle 第 70 行:

export JAVA_HOME=/usr/lib/jvm/default-java

注释掉这一行就解决了问题,Gradle 找到了 Java 二进制文件的正确路径.

Commenting this line out solves the problem, and Gradle finds the correct path to the Java binary.

如果您只是从他们的网站下载二进制文件,则不会出现此问题,这是 Ubuntu 存储库版本的问题.13.10 版本似乎还有其他一些问题.

If you just download the binary from their website it does not have this problem, It's an issue with the Ubuntu repo version. There also seem to be some other issues with 13.10 version.

这篇关于即使设置正确,Gradle 也会发现错误的 JAVA_HOME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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