简体   繁体   English

Cordova无法在Java 9中使用。如何仅为Cordova设置特定的jdk?

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

Due to this issue , at the moment Cordova isn't able to run on Java 9 (please correct me if I'm wrong). 由于这个问题 ,目前Cordova无法在Java 9上运行(如果我错了,请纠正我)。

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. 这里讨论了一个类似的问题,但是建议的解决方案涉及删除Java 9或将JAVA_HOME环境变量重置为指向Java 8,但是这两者都有副作用,即所有其他Java应用程序都将在Java 8上运行。

So how do you set Cordova to use Java 8, having the rest of applications still on Java 9? 那么,如何将Cordova设置为使用Java 8,而其余的应用程序仍在Java 9上呢?

... 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. ...将JAVA_HOME环境变量重置为指向Java 8,但是[副作用]是所有其他Java应用程序都将在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. 创建一个包含此文件的文件(例如mycordova.sh ),使其可执行,并将其放在您的Shell的命令搜索路径中。

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

Running that command runs cordova using Java 8 without interfering with other applications. 运行该命令可使用Java 8运行cordova 而不会干扰其他应用程序。


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. 更新 -如果建议的解决方法是使用alternatives来进行更改,则表明cordova启动器/脚本未使用JAVA_HOME查找java命令。 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. 如果cordova是包装器脚本,则将其复制并编辑以使用要使用的java命令(等)的版本。

  • 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. 如果不是,那么在mycordova.sh脚本中(请参见上文),还更新PATH变量,以使Java 8 JRE的bin目录位于包含alternatives管理的java链接的目录之前。 That will work ... provided that the standard cordova launcher has not hard wired /usr/bin/java 只要标准的科尔多瓦启动器没有硬连线/usr/bin/java ,那将起作用。


UPDATE 2 - Final script for mycordova.sh is: 更新 2-mycordova.sh的最终脚本是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM