Cordova build : Error :Failed to run "java -version "

4.4k views Asked by At

I've installed the latest Apple update for Java, here is what the terminal now says:

$ java -version  
java version "1.8.0.0_25"  
Java(TM) SE Runtime Environment (build 1.8.0.0_25-b18)  
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)    

After that I still have the following result:

$ cordova build
Running command...  

[Error: Failed to run "java - version ", make sure that you have a JDK installed.
You can get it from htpp://...

[Error: ERROR : build one of the platforms : Eroor:C:\User\HelloWorld\paltforms\android\cordova\build.bat:Command faild with exit code 2...]

Looking around there seems to be huge confusion on how to activate Java.
Do I now also need to download and install the Oracle Java package from the following link?link

3

There are 3 answers

3
Roni Sommerfeld On BEST ANSWER

Configure your .bash_profile file...

nano ~/.bash_profile

Adding is line:

export JAVA_HOME=$(/usr/libexec/java_home) export PATH=${JAVA_HOME}/bin:$PATH export PATH=/usr/local/bin:$PATH

0
Yvan On

Note that even if cordova/phonegap indicate java -version, it doesn't say that you need the JDK and not the JRE.

java -version returns the JRE version.

So you will have an answer for java -version, but you won't have the necessary JDK.

Install the Java JDK, and that should do the trick.

1
Shao Khan On

in my case i added

D:\Program Files\Java\jdk1.8.0_73\bin

to my enviroment variables and restarted my IDE. The \bin folder is important Be sure you added the JAVA_HOME Variable under your Userenviroment and not under the System.