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

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?

解决方案

... 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值