即使在 Windows 8 Enterprise 上设置了路径,也无法运行 JAVA - Cordova
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22868472/
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
Failed to run JAVA even though path is set on Windows 8 Enterprise - Cordova
提问by Bogdan Rybak
I have made a new Ionic / Cordova project and I'm trying to build it on windows 8.1. I installed JDK and JRE 7 as well as android sdk and ant and added them to my path using the following instructions.
我制作了一个新的 Ionic/Cordova 项目,我正在尝试在 Windows 8.1 上构建它。我安装了 JDK 和 JRE 7 以及 android sdk 和 ant,并使用以下说明将它们添加到我的路径中。
cordova platform add android not working while listing Android targets
在列出 Android 目标时,cordova 平台添加 android 不起作用
When I execute ionic platform add android
or cordova
I am still getting the following error:
当我执行ionic platform add android
或cordova
我仍然收到以下错误:
C:\Users\BogdanR\.cordova\lib\android\cordova.4.0\bin\node_modules\q\q.js:126
throw e;
^
Error: Failed to run 'java -version', make sure your java environment is set up
including JDK and JRE.
Your JAVA_HOME variable is C:\Program Files\Java\jdk1.7.0_51
Error: Command failed: 'java' is not recognized as an internal or external command,
operable program or batch file.
at C:\Users\BogdanR\.cordova\lib\android\cordova.4.0\bin\lib\check_reqs.js:62:22
at ChildProcess.exithandler (child_process.js:641:7)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Socket.<anonymous> (child_process.js:956:11)
at Socket.EventEmitter.emit (events.js:95:17)
at Pipe.close (net.js:466:12)
Error: cmd: Command failed with exit code 8
at ChildProcess.whenDone (C:\nodist\bin\node_modules\cordova\src\superspawn.js:112:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)
Unable to add platform android. Please see console for more info.
I tried modifying both system variables and user PATH variables.
我尝试修改系统变量和用户 PATH 变量。
THE WEIRD THING is that I can type in java -version
and it works:
奇怪的是我可以输入java -version
并且它有效:
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
I am using nodist to manage npm if that is of any relevance.
如果有任何相关性,我正在使用 nodist 来管理 npm。
采纳答案by Bogdan Rybak
There was a bad entry in the path that corrupted my whole system path.
路径中有一个错误的条目损坏了我的整个系统路径。
C:\Program Files\Microsoft SQL Server\110\Tools\Binn";C:\Program Files\Microsoft\Web Platform Installer\;
C:\Program Files\Microsoft SQL Server\110\Tools\Binn";C:\Program Files\Microsoft\Web Platform Installer\;
Seems like that quotation mark is an entry added by SQL Server installation or web platform. I never added those to the path so it might be the installers fault?
好像那个引号是 SQL Server 安装或 web 平台添加的条目。我从未将它们添加到路径中,所以这可能是安装程序的错误?
回答by Bogdan Rybak
There is one thing you can try is to set this variable JAVA_HOME to C:\Program Files\Java\jdk1.7.0_51\bin
您可以尝试的一件事是将此变量 JAVA_HOME 设置为 C:\Program Files\Java\jdk1.7.0_51\bin
Since you are using Windows, you can go to Control Panel to update it.
由于您使用的是 Windows,您可以转到控制面板进行更新。
You were able to run java -version
probably because it's included in the User's path.
您能够运行java -version
可能是因为它包含在用户的路径中。
回答by Kerad44
After I ran into the same issue, the following steps seems to have fixed it:
在我遇到同样的问题后,以下步骤似乎已修复它:
PATH
needs to contain the bin folder of the Java installation pathC:\Program Files\Java\jdk1.8.0_05\bin
make sure thebin
is includedJAVA_HOME
needs to be set to the root of that Java installation folder, in my caseC:\Program Files\Java\jdk1.8.0_05
PATH
需要包含Java安装路径的bin文件夹,C:\Program Files\Java\jdk1.8.0_05\bin
确保bin
包含JAVA_HOME
需要设置为该 Java 安装文件夹的根目录,在我的情况下C:\Program Files\Java\jdk1.8.0_05
回答by www.amitpatil.me
In my case, i had multiple java instalations, and whenever i tried to print "echo %java_home%" command on command prompt, it always used to return "%java_home%" as it is.
就我而言,我有多个 Java 安装,每当我尝试在命令提示符下打印“echo %java_home%”命令时,它总是按原样返回“%java_home%”。
So i uninstalled all the java versions and then installed it again, and whoola, it worked.
所以我卸载了所有的 java 版本,然后再次安装,哇,它工作了。
Hope this helps someone.
希望这可以帮助某人。
回答by MiTan
In my case, It said "JAVA_HOME variable is unvalid, C:\Program Files\Java\jdk1.7.0_51". Then I added a quotation mark to JAVA_HOME. Just like "C:\Program Files\Java\jdk1.7.0_51". Finally It works. May This can be helpful
就我而言,它说“JAVA_HOME 变量无效,C:\Program Files\Java\jdk1.7.0_51”。然后我给JAVA_HOME加了个引号。就像“C:\Program Files\Java\jdk1.7.0_51”。最后它起作用了。这可能会有所帮助