Cordova picking up wrong version of java - java

I am trying to run
cordova build android
It gives the following error
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/home/bappaditya/Softwares/android-studio (recommended setting)
ANDROID_HOME=/home/bappaditya/Softwares/android-studio (DEPRECATED)
Requirements check failed for JDK 8 ('1.8.*')! Detected version: 12.0.2
Check your ANDROID_SDK_ROOT / JAVA_HOME / PATH environment variables.
I can see that it has picked up ANDROID_HOME and ANDROID_SDK_ROOT but not the correct version of java
My current environment
>java -version
openjdk version "1.8.0_275"
OpenJDK Runtime Environment (build 1.8.0_275-8u275-b01-0ubuntu1~20.04-b01)
OpenJDK 64-Bit Server VM (build 25.275-b01, mixed mode)
>echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64
>echo $PATH
/home/bappaditya/.cargo/bin:/opt/gradle/gradle-5.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/bappaditya/bin:/usr/lib/jvm/java-8-openjdk-amd64/bin
As you can see the JAVA 8 is installed and set as default. Why cordova complaining about java version?

It seems cordova uses javac to identify the version and not java.
So the command that really shows the version cordova gets when looking for Java is:
javac -version
In my case, even though I had identical versions to what you have in your environment, it turned out my javac was pointing to a newly updated Java (from Ubuntu updates)
To fix it, I used the update-alternatives command and set javac back to my 1.8.0 version as follow:
sudo update-alternatives --config javac

Related

JAVA_HOME is not defined correctly. ubuntu

When I check maven Version
$ mvn -version
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-8-oracle/bin/java
How to solve it ?
these are my java jdk version.
$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.18.04.1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
Make sure your JAVA_HOME variable is set to the JRE folder, like this:
/usr/lib/jvm/java-8-oracle/jre
To further improve your setup, you can let Java pick the correct version by putting this in your JAVA_HOME (this assumes you used the Oracle installer):
export JAVA_HOME=$(/usr/libexec/java_home)
If this doesn't work for you, make sure permissions are set correctly (Execute permissions on the binaries)

Need help installing Java 8 on Mac OS X

I am trying to upgrade to: Java 8 Update 66, from Java 6, on my Mac running Mac OS X 10.10.5. I downloaded the Java Update .dmg file: re-8u66-macosx-x64.dmg. When I run the installer I get the message it installed properly. When I confirmed the install via the FireFox Browser at this URL:
https://java.com/en/download/installed.jsp
It reports:
Congratulations!
You have the recommended Java installed (Version 8 Update 66).
However, If I open a terminal window and enter: java -version
It reports:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)
Can someone please explain what is going on here? Do I need to update a link somewhere?
Thanks.
Please check your PATH variable, and make sure that the java directories in the path match the directories in your computer. It should be the bin folder of the JAVA_HOME environment directory. Also check that JAVA_HOME environment variable is set to the jdk folder of your java installation.
There's two option based on my experience to fix this issue, fisrt uninstalled the java on your computer and reinstalled using the latest version.
Second, run a different version of Java, either specify the full path, or use the java_home tool:
List your installed java version:
$ /usr/libexec/java_home -V
In this case you are using java 8 so you can run command
$ /usr/libexec/java_home -v 1.8 --exec javac -version
If you want to make easy to switch your java version you can create alias in ~/.bashrc
alias java6="export JAVA_HOME=$(/usr/libexec/java_home -v 1.6);echo 'using Java 6'"
alias java8="export JAVA_HOME=$(/usr/libexec/java_home -v 1.8);echo 'using Java 8'"
Hope it help

OSX Java upgrade doesn't reflect command line -version. Why?

I upgraded java on my osx 10.9.4 machine using the suggested method from the java web site
It successfully updated, but when trying to run Eclipse I get an error:
Version 1.6.0_65 of the JVM is not suitable for this product.
Version 1.7 or greater is required.
When I access java settings through the applet in the control panel, it shows Java 7 Update 65, but when I type java -version in the console, it shows 1.6.0_65 (response shown below):
| => java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)
As far as I know, there is only one java on the box. "which java" returns /usr/bin/java and type -a java returns only /usr/bin/java also. /usr/bin/java is obviously the older version, but I'd like to use the updated one. Can someone please tell me how to update the /usr/bin/java version and/or how to link the applet version so that Eclipse will use the updated one?
Take a look at oracle documentation here:
http://docs.oracle.com/javase/7/docs/webnotes/install/mac/mac-jdk.html
It says:
To run a different version of Java, either specify the full path, or
use the java_home tool:
/usr/libexec/java_home -v 1.7.0_06 --exec javac -version
The /usr/libexec/java_home is a link to your jdk directory that should be located under:
/Library/Java/JavaVirtualMachines/jdk<major>.<minor>.<macro[_update]>.jdk
I think your java_home link is pointing to your jdk6. You can check it doing a ls -l /usr/libexec/

ant - JAVA_HOME is not defined correctly

I have installed java with the command sudo apt-get install openjdk-7-jdk and set the java home and path.But when I am trying to use ant I
JAVA_HOME is not defined correctly.
We cannot execute /usr/local/java/jre1.7.0_60/bin/java
Please help me how to resolve this error.
which java ----> /usr/bin/java
java -version ---->java version "1.6.0_31"
OpenJDK Runtime Environment (IcedTea6 1.13.3) (6b31-1.13.3-1ubuntu1~0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)
echo $JAVA_HOME -----> /usr/local/java/jre1.7.0_60
I had same problem than you. Try using Oracle jdk instead openjdk
To change OpenJdk by Oracle JDK you can do (you have to download oracle jdk first):
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jre1.6.0_37/bin/java" 1
Here you have a detailed explanation:
http://hendrelouw73.wordpress.com/2012/11/09/how-to-install-oracle-java-6-0-37-on-ubuntu-12-04-linux/
You can set your environment by doing:
vi /etc/environment
in my case I did:
PATH="/usr/lib/jvm/java-6-sun/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
JAVA_HOME="/usr/lib/jvm/java-6-sun/"
and it solved my problem
Ant requires JDK and you have installed JRE. So ant is throwing such an error.
So, just Uninstall JRE and then install JDK, this will solve your error.

Error: Could not find or load main class version

I have downloaded Java on mac mavericks system. But when I type on terminal to see the Java version using command:
java version
I get the following error
Could not find or load main class version
I went to oracle website and tried a check to see if Java is installed on my system,which confirmed the Java7 is installed on the system. But why can I not see version in terminal?
Try
java -version
Without the minus sign it is trying to load a program called version.
java –version
will cause the same error (copied from webpage) as "–" is an em dash
java -version is the command to check java version
Download latest Java SE from Oracle site and install it. Then reopen cmd and check java version using java -version.
Set the Java path to bin and check it's version also. Both java and javac should be on same version.
In my case:
C:\Users\darshan>java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
C:\Users\darshan>javac -version
javac 1.8.0_121

Categories