Home > database >  "Your JAVA_HOME is invalid: C:\Program Files\Java\jdk1.8.0_301" when building ionic app
"Your JAVA_HOME is invalid: C:\Program Files\Java\jdk1.8.0_301" when building ionic app

Time:10-13

I have tried every which way to declare JAVA_HOME in my system variables, but I keep getting the following error when running 'ionic Cordova build --release android'

Failed to run "javac -version", make sure that you have a JDK version 8 installed.
You can get it from the following location:
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Your JAVA_HOME is invalid: C:\Program Files (x86)\Java\jdk1.8.0_301

I've tried appending it with "bin", I've tried wrapping C: Program Files (x86) in double quotes, I've tried uninstalling and reinstalling java, and I always get the same error. When I run echo %JAVA_HOME% it gives me:

C:\Program Files (x86)\Java\jdk1.8.0_301

I am at my wit's end. Can anyone help me figure out what's wrong?

CodePudding user response:

I can see a couple of problems here. The following instructions should help you resolve the issue:

  1. The installation path has x86 which suggests that you have installed a 32-bit version of JDK. If your OS is 64 bit (which is mostly the case), download and install the 64 bit JDK.
  2. While installing, the installer gives you an opportunity to change the installation location. The default suggested location has space that may be problematic and therefore I recommend you change it to something like C:\jdk.
  3. Append the path of JDK bin folder to the PATH environment variable e.g. if the path of bin folder is C:\jdk\jdk1.8.0_301\bin, append this to the PATH environment variable and also move it to the top position.
  4. Create a new environment variable, JAVA_HOME and put C:\jdk\jdk1.8.0_301 (i.e. the path, one level above the bin folder) as the value into it.
  5. Finally, start a new cmd window and test the command, java -version.
  • Related