Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

bash - Gradle does not recognize the JAVA_HOME I have set

I have set my JAVA_HOME to /usr/lib/jvm/java-7-oracle, which contains a valid JVM, but gradle insists on using /usr/lib/jvm/default-java and complains about JAVA_HOME:

$ echo $JAVA_HOME 
/usr/lib/jvm/java-7-oracle
$ ls $JAVA_HOME
bin  COPYRIGHT  db  include  jre  lib  LICENSE  man  README.html  release  src.zip  THIRDPARTYLICENSEREADME-JAVAFX.txt  THIRDPARTYLICENSEREADME.txt
$ gradle assemble

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.

How can I fix this and have gradle use my valid JAVA_HOME?

Note: My JAVA_HOME is set by ~/.bashrc using export JAVA_HOME="/usr/lib/jvm/java-7-oracle"

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

it is quite common issue. Just go to your gradle home directory and bin, for example:

/home/user/gradle-2.0/bin

and there you should have gradle script, I am on a Windows machine now so I have gradle.bat, probably you will have gradle.sh or something like this. In that file, find the line:

set JAVA_HOME=%JAVA_HOME:"=%

or as I can see you are on linux so there will be "export" and change it to your java home directory for example:

export JAVA_HOME=/usr/lib/jvm/java-7-oracle

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...