1

Due to this issue, at the moment Cordova isn't able to run on Java 9 (please correct me if I'm wrong).

A similar question was discussed here, but the proposed solutions involve the removal of Java 9, or the reset of the JAVA_HOME environment variable to point to Java 8, but both has the side effect that all the other Java applications will run on Java 8.

So how do you set Cordova to use Java 8, having the rest of applications still on Java 9?

oidualc
  • 1,104
  • 1
  • 14
  • 21

1 Answers1

2

... the reset of the JAVA_HOME environment variable to point to Java 8, but [that] has the side effect that all the other Java applications will run on Java 8.

Only if you do it the wrong way!

Create a file (say mycordova.sh) containing this, make it executable and put it on your shell's command search path.

#!/bin/sh
export JAVA_HOME=/path/to/java8/home
cordova "$@"

Running that command runs cordova using Java 8 without interfering with other applications.


UPDATE - If the work-around proposed is to use alternatives to change, that means that the cordova launcher / script, is not using JAVA_HOME to find the java command. You can deal with that too. There are a couple of possibilities:

  • If cordova is a wrapper script, then copy it and edit it to use the version of the java command (etc) that you want to use.

  • If not then in your mycordova.sh script (see above) also update the PATH variable so that the Java 8 JRE's bin directory is ahead of the directory containing the java link that alternatives manages. That will work ... provided that the standard cordova launcher has not hard wired /usr/bin/java


UPDATE 2 - Final script for mycordova.sh is:

#!/bin/sh
export JAVA_HOME=/path/to/java8/home
export PATH=/path/to/java8/bin/:$PATH
cordova "$@"
oidualc
  • 1,104
  • 1
  • 14
  • 21
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • My bad, as discussed in the linked question the reset of the JAVA_HOME alone is not enough, it's required a `sudo update-alternatives --config javac` or in my case a `sudo archlinux-java set java-8-openjdk`. Considered that, this solution outputs this: `$ mycordova.sh run android` `ANDROID_HOME=/home/myhome/devel/Android/Sdk` `JAVA_HOME=/usr/lib/jvm/java-8-openjdk` `Error: Requirements check failed for JDK 1.8 or greater` – oidualc Oct 18 '17 at 10:57