- Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java when i run gradle command in terminal
- 4 Answers 4
- Windows 10 Gradle: JAVA_HOME is set to an invalid directory
- 8 Answers 8
- Java home supplied via ‘org.gradle.java.home’ is invalid. Invalid directory: /usr/local/java/jdk1.8.0_05
- 10 Answers 10
- Gradle finds wrong JAVA_HOME even though it’s correctly set ubuntu 13.10
- IntelliJ IDEA Gradle sync: Problem with setting Gradle’s Java home to some JDKs
Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java when i run gradle command in terminal
I am working in Ubuntu 16.04. I need to install gradle and the gradle is installed when i checked with sudo apt list —installed command but when i use gradle -version command it shows the following error, JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java In sudo vim /etc/environment file,
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/" http_proxy="http://username:password@IP:port no/" https_proxy="https://IP:port no/" ftp_proxy="ftp://IP:port no/"
4 Answers 4
On a 64bit openSuse 64 42.1 box;
/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/jre/bin/java
export JAVA_HOME=/usr/lib64/jvm/jre-1.8.0-openjdk
is the path that worked and allowed java emulator to run.
So i think we have to manually browse our file system and see what path to choose.
Today I faced this problem. I am using the default java that comes with your linux distro (so in my case, linux mint).
java: /usr/bin/java /usr/share/java
So, I opened /user/bin . There was a link to Java . I right clicked it and selected follow original link . This lead me to /usr/lib/jvm/java-11-openjdk-amd64/bin/java . So now that I know where this java is, I opened my .bashrc file, and edited the JAVA_HOME. So for my case,
## My Custom variables export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH
Now if you are using some other java (say you downloaded from oracle and extracted the zip file . ), then you have to add that location. So for example, if your java is in /home/user/.sdkman/candidates/java/current , then
export JAVA_HOME=/home/user/.sdkman/candidates/java/current export PATH=$JAVA_HOME/bin:$PATH
Windows 10 Gradle: JAVA_HOME is set to an invalid directory
I was trying to run ./gradlew bootRun in both Git Bash and PowerShell, and got this error: ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files\Java\jre1.8.0_121 The gradlew file is inside the project directory that cloned from git. It is a practice project from Spring official guide. There’s also a gradle.bat file with these lines:
:findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%\bin\java.exe
I also tried to run Eclipse EE, which got no problem. The environment setting should be no problem.
8 Answers 8
In addition to Ernest’s answer, the JAVA_HOME it wants is the actual directory, not the bin folder like the path wants for javac. Took me a while to work that out
Looks like your JAVA_HOME variable resolves to a JRE installation directory. But as you’re talking about Gradle, you’re surely trying to build/compile code.
If you have a JDK installed, change JAVA_HOME variable to point to it. The folder name should typically start with «jdk». Otherwise, you have to install a Java Development Kit.
You could also try exporting the variable manually before running gradle on the command line ( SET JAVA_HOME= )
Please set the JAVA_HOME variable location to the path to JDK instead of JRE.
If that is correctly set, check the environment variables in Edit mode. In my case, I found that a semicolon was appended to the JAVA_HOME environment variable at the end.
- Open the environment variables list.
- Select the variable and click Edit.
- Remove the semicolon and Save.
Closed the settings and checked the path in cmd using echo %JAVA_HOME%, and ran gradle -v.
Note: Check the variable value by clicking the Edit button as we cannot see the semicolon instead. Windows adds a semicolon so that the same variable can be used as the path to multiple locations.
Added picture for reference:
Found a solution I hadn’t seen before in my googling.
Open up your gradlew.bat in some editor. On line 34-ish you will see this:
:findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%\bin\java.exe if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation.
add this line to the error message: echo %JAVA_EXE%
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo %JAVA_EXE% echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation.
Then run your gradlew.bat file.
The error should now appear again, but with the added echo of the path to JAVA_EXE. In my case it was echoing \bin\java.exe and NOT the full path C:\. \Java\jre1.8.0_251\bin\java.exe
set JAVA_EXE=C:\. \Java\jdk1.8.0_261\bin\java.exe
The value is now hardcoded, true, but it worked. I don’t know why gradle doesn’t concat the variable name into the path.
Java home supplied via ‘org.gradle.java.home’ is invalid. Invalid directory: /usr/local/java/jdk1.8.0_05
I’m using gradle 2.9, intellij and Win10 for spring development. In one particular project I encountered this error:
Java home supplied via 'org.gradle.java.home' is invalid. Invalid directory: /usr/local/java/jdk1.8.0_05
10 Answers 10
Finally I found my solution. In the project root I found gradle.properties configure this java home
org.gradle.java.home=/usr/local/java/jdk1.8.0_05
I remove and build it properly.
There are two gradle.properties files being checked: the one in the project, and the one in the ~/.gradle directory.
- Check the global gradle configuration in C:\Users\\.gradle
- In your android project you will have a file named gradle.properties
- Delete org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_144
The accepted answer explicitely asks to look for the properties file in the project root directory. However there are global and local gradle properties and either can be responsible for setting this property value. This one refers to global settings and is in my opinion not the same solution, even though it targets the same attribute. +1
- In your android project you will have a file name gradle.properties.
- Open up that file, there will a line
- You will have to change this line, insert your jdk setup location, most important use double backslashes «\\» like above in your path.
For anyone on MacBooks, you might want to check if the file in /Users/username/.gradle/gradle.properties has the correct JDK path provided.
I was receiving the following message in Android Studio:
Value ‘/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home’ given for org.gradle.java.home Gradle property is invalid (Java home supplied is invalid)
My gradle.properties file had the following line:
And I had to change it to the following:
org.gradle.java.home=/Applications/Android Studio 4.1.3.app/Contents/jre/jdk/Contents/Home Since I renamed Android Studio.app to Android Studio 4.1.3.app since I have multiple installations.
Gradle finds wrong JAVA_HOME even though it’s correctly set ubuntu 13.10
This sort of question was also answered on Stack Overflow. Turns out that there is an export in /usr/bin/gradle that probably shouldn’t be there.
One solution is to comment out that export line. Another solution is to use a PPA that has a different/newer Gradle.
I tried creating a dynamic symbolic link in my .bash_profile (because I use Jenv on Mac) at ln -s /usr/lib/jvm/default-java $JAVA_HOME and it did not resolve the issue for me. Would rather not edit my Gradle distro executor, but i guess if I have to.
You have incorrectly set your JAVA_HOME variable. It shouldn’t be pointing to the jre but to the jdk.
Set your JAVA_HOME variable to /usr/lib/jvm/java-7-oracle .
This is the problem with the gradle which is appending /bin/java JAVACMD=»$JAVA_HOME/bin/java» to your JAVA_HOME path in its scripts. so go to your gradle-3.3/bin location of your gradle scripts and edit the gradle file using gedit.
if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation."
this is the code snippet which is appending the java path hence results in an invalid path since you have already included /bin/java in your JAVA_HOME. so either change it here or remove the /bin/java from your JAVA_HOME path variable from the /etc/environment. I have removed the /bin/java from the JAVA_HOME path and it worked fine for me.
IntelliJ IDEA Gradle sync: Problem with setting Gradle’s Java home to some JDKs
in my (global) gradle.properties file. Also, no problem without it (with nothing set). But if replace it with one of below configurations (all paths are valid):
- org.gradle.java.home=C:/Program Files/Java/openjdk-9.0.4
- org.gradle.java.home=C:/Program Files/Java/openjdk-10.0.1
- org.gradle.java.home=C:/Program Files/Java/openjdk-11.0.1
- org.gradle.java.home=C:\\Program Files\\Java\\oraclejdk-11.0.1
then I will get an error message (same for each) after I save the file and import Gradle changes in IntelliJ IDEA:
Unable to start the daemon process. This problem might be caused by incorrect configuration of the daemon. For example, an unrecognized jvm option is used. Please refer to the user guide chapter on the daemon at https://docs.gradle.org/5.0/userguide/gradle_daemon.html
Please read the following process output to find out more:
OpenJDK 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0 Error: Could not find or load main class java.base.java.lang=ALL-UNNAMED Caused by: java.lang.ClassNotFoundException: java.base.java.lang=ALL-UNNAMED
The note is the issue is only for IDE Gradle sync. Gradle tasks themselves work correctly (independent from IDE)! Even when I run gradle —status (see here about it) can see everything is OK and daemon is running using JDK 11:
>gradlew --status PID STATUS INFO 10668 IDLE 5.0
And the path of PID: 10668 :
>wmic process where "processId=10668" get Name, ProcessID, ExecutablePath ExecutablePath Name ProcessId C:\Program Files\Java\openjdk-11.0.1\bin\java.exe java.exe 10668