无法在 Mac 中找到“JAVA_HOME”环境变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49530633/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 03:03:05  来源:igfitidea点击:

Failed to find 'JAVA_HOME' environment variable in Mac

javanode.jsgitcordovajava-home

提问by ToniTJK

I'm new on Mac, so I installed Cordova (Node, Git, Grandle) but I can't execute it in my mobile phone, I mean I can't do "sudo Cordova run android" because it can't find "JAVA_HOME". When I installed I put this variable before... (It is a headache )

我是 Mac 新手,所以我安装了 Cordova(Node、Git、Grandle)但我无法在手机中执行它,我的意思是我无法执行“sudo Cordova run android”,因为它找不到“ JAVA_HOME”。当我安装时,我把这个变量放在了......(这是一个令人头疼的问题)

I tried to open the bash_profile but I didn't find it and if I open in terminal it always open a new file.

我试图打开 bash_profile 但我没有找到它,如果我在终端中打开它总是打开一个新文件。

If I do echo $JAVA_HOME, it is the result:

如果我做 echo $JAVA_HOME,结果是:

echo $JAVA_HOME

/usr/libexec/java_home

/usr/libexec/java_home

And this is my error:

这是我的错误:

sudo cordova run android --target=ZY223T38PM

(node:1369) UnhandledPromiseRejectionWarning: CordovaError: Failed to find 'JAVA_HOME' environment variable. Try setting setting it manually. at /Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/lib/check_reqs.js:185:35 at _rejected (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:864:24) at /Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:890:30 at Promise.when (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:1142:31) at Promise.promise.promiseDispatch (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:808:41) at /Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:624:44 at runSingle (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:137:13) at flush (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:125:13) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9) (node:1369) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:1369) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

(节点:1369)未处理的PromiseRejectionWarning:CordovaError:无法找到“JAVA_HOME”环境变量。尝试手动设置。在 /Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/lib/check_reqs.js:185:35 at _rejected (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q /q.js:864:24) at /Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:890:30 at Promise.when (/Users/tonitorres/Dropbox/ HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:1142:31) at Promise.promise.promiseDispatch (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/ q.js:808: 41) at /Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova/node_modules/q/q.js:624:44 at runSingle (/Users/tonitorres/Dropbox/HardwareHome/hardwareHome/platforms/android/cordova /node_modules/q/q.js:137:13) 在 _combinedTickCallback (内部/ process/next_tick.js:131:7) 在 process._tickCallback (internal/process/next_tick.js:180:9) (node:1369) UnhandledPromiseRejectionWarning:未处理的承诺拒绝。这个错误要么是因为在没有 catch 块的情况下抛出了异步函数,要么是因为拒绝了一个没有用 .catch() 处理过的承诺。(rejection id: 1) (node:1369) [DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。在将来,

采纳答案by nazar_art

You didn't install JAVA_HOMEcorrectly, therefore it fails.

您没有JAVA_HOME正确安装,因此它失败了。

You have to do it like following:

你必须这样做:

After installation you have to add installed java to system variable:

安装后,您必须将已安装的 java 添加到系统变量中:

Run in terminal for verification:

在终端中运行以进行验证:

java -version

java -version

The output should be something like:

输出应该是这样的:

java version "1.8.0_06-ea"
Java(TM) SE Runtime Environment (build 1.8.0_06-ea-b13)
Java HotSpot(TM) 64-Bit Server VM (build 23.2-b04, mixed mode)

After this check, you can import java to your IDE.

在此检查之后,您可以将 java 导入到您的 IDE 中。