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

查看:1346
本文介绍了即使设置正确,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

此外,我已经检查过,在$中没有重复的JAVA_HOME定义c $ c> .bash_profile 或 / etc / profile

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

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 repo版本的问题。 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天全站免登陆