Cordova isn't working with Java 9. How to set a specific jdk ONLY for Cordova?

前端 未结 1 1359
借酒劲吻你
借酒劲吻你 2021-01-24 09:35

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 solution

相关标签:
1条回答
  • 2021-01-24 09:58

    ... 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 "$@"
    
    0 讨论(0)
提交回复
热议问题