I've recently tried changing my environment variables to set paths to javac.exe (among other things). It was working fine until, all of a sudden, I started getting this error. For example, I declared a JAVA_HOME variable to be
我最近尝试更改环境变量以设置到javac的路径。exe(在其他事物之中)。它运行得很好,直到突然,我开始犯这个错误。例如,我声明了一个JAVA_HOME变量。
C:\Program Files\Java\jdk1.7.0_25
C:\Program Files\Java\ jdk1.7.0_25
After which, I add
之后,我添加
%JAVA_HOME%\bin
% JAVA_HOME % \ bin
to the PATH variable, but this gives me an error:
对于路径变量,但这给了我一个错误:
'C:\Program' is not recognized as an internal or external command, operable command or batch file.
“C:\程序”不被识别为内部或外部命令、可操作的命令或批处理文件。
This error makes it seem like it's running into problems with the space in "Program Files". This is weird, though, since it wasn't doing this for a good while, then started. Further, there are other variables with spaces in them that work just fine. I've tried deleting the variable and recreating it, putting quotes around JAVA_HOME (which goes to the correct path, but does not find javac.exe correctly)..
这个错误使得它似乎在“程序文件”中遇到了问题。但是,这很奇怪,因为它并不是在一段时间内完成的,然后就开始了。此外,还有一些其他的变量,它们的工作空间很好。我尝试过删除变量并重新创建它,在JAVA_HOME周围加上引号(这是正确的路径,但是没有找到javac)。exe正确)。
Any tips on what I might do?
有什么建议吗?
This is on Windows 7.
这是在Windows 7上。
EDIT:
编辑:
The environment variables were set by going Control Panel > Advanced System Settings > Environment Variables. The value of the variables were set by copying the address of the folder I want through an Explorer window. I added it to the PATH environment variable by appending the address with a space between the preceding variable and a semicolon at the end, as such:
环境变量的设置是通过控制面板>先进的系统设置>环境变量。变量的值是通过在Explorer窗口中复制我想要的文件夹的地址来设置的。我将其添加到PATH环境变量中,通过在前面的变量与末尾的分号之间添加一个空格,如下所示:
C:\Users\Demo_User_1\AppData\Roaming\npm; %JAVA_HOME%
C:\Users\ Demo_User_1 \ AppData \ \ npm漫游;% JAVA_HOME %
where the JAVA_HOME variable is defined as such:
JAVA_HOME变量的定义如下:
C:\Program Files\Java\jdk1.7.0_25
C:\Program Files\Java\ jdk1.7.0_25
I test the value of the variable through a command prompt by typing %JAVA_HOME%, and that's where I get the resulting error of "'C:\Program' is not recognized..."
通过键入%JAVA_HOME%,我通过命令提示来测试变量的值,这是我得到“'C:\程序'的结果错误的地方……”
The results of 'set' are as follows:
“set”的结果如下:
C:\Users\Demo_User_1>set
ALLUSERSPROFILE=C:\ProgramData
ANDROID_HOME=C:\Users\Demo_User_1\Desktop\Android\adt-bundle-windows-x86_64-2013
0717\sdk
APPDATA=C:\Users\Demo_User_1\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=DEMO_USER_1-HP
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\Demo_User_1
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_25
LOCALAPPDATA=C:\Users\Demo_User_1\AppData\Local
LOGONSERVER=\\DEMO_USER_1-HP
NUMBER_OF_PROCESSORS=4
OnlineServices=Online Services
OS=Windows_NT
Path=C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Clien
t\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files
(x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program
Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\
x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\I
ntel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Managem
ent Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engin
e Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Compone
nts\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\Wir
elessCommon\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files
(x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows
Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\
Tools\Binn\;C:\Program Files\nodejs\; C:\Users\Demo_User_1\Desktop\Android\adt-b
undle-windows-x86_64-20130717\sdk/platform-tools; C:\Users\Demo_User_1\Desktop\A
ndroid\adt-bundle-windows-x86_64-20130717\sdk\tools; %JAVA_HOME%; %ANT_HOME%/bin
; C:\Program Files\Java\jdk1.7.0_25\bin; C:\Users\Demo_User_1\AppData\Roaming\np
m; "%JAVA_HOME%"; ;C:\Users\Demo_User_1\Desktop\Android\adt-bundle-windows-x86_6
4-20130717\sdk/tools; C:\Users\Demo_User_1\Desktop\Android\adt-bundle-windows-x8
6_64-20130717\sdk/platform-tools
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PCBRAND=Pavilion
Platform=MCD
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=3a09
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\DEMO_U~1\AppData\Local\Temp
TMP=C:\Users\DEMO_U~1\AppData\Local\Temp
USERDOMAIN=Demo_User_1-HP
USERNAME=Demo_User_1
USERPROFILE=C:\Users\Demo_User_1
VS110COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools
\
windir=C:\Windows
windows_tracing_flags=3
windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log
5 个解决方案
#1
21
Okay, that makes it clearer.
好了,这就清楚了。
There are two main problems here.
这里有两个主要问题。
First of all, the reason you're getting 'C:\Program' is not recognized...
is, of course, because it contains spaces. The fact that you have it quoted in the PATH environment variable has no relation to how %JAVA_HOME% is interpreted at the prompt. You have two options.
首先,你得到“C:\程序”的原因是不被认可的……当然,因为它包含空格。在PATH环境变量中引用的事实与如何在提示符中解释%JAVA_HOME%是没有关系的。你有两个选择。
- Quote it when you define the variable, i.e. set JAVA_HOME to
"C:\Program Files\Java\jdk1.7.0_25"
- 当您定义变量时引用它,例如将JAVA_HOME设置为“C:\程序文件\Java\jdk1.7.0_25”
- Quote it when you invoke it. Type
"%JAVA_HOME%\bin"
at the prompt. Of course, you'll get the "not recognized as an internal or external command, operable program or batch file" error unless you end the path with an executable (e.g."%JAVA_HOME%\bin\javac.exe"
), but you'll see that this way it complains about '"C:\Program Files\Java\jdk1.7.0_25"' rather than 'C:\Program'. - 当你调用它时引用它。在提示符处键入“%JAVA_HOME%\bin”。当然,您将获得“不被识别为内部或外部命令、可操作程序或批处理文件”的错误,除非您以可执行程序结束该路径(例如:“%JAVA_HOME%\bin\javac.exe”,但是您会看到这种方式会抱怨“C:\程序文件\Java\jdk1.7.0_25”,而不是“C:\程序”。
Second, you can't use environment variables in the path. You can use environment variables when you set the path at the command prompt. For example,
其次,您不能在路径中使用环境变量。当您在命令提示符中设置路径时,您可以使用环境变量。例如,
set PATH=%PATH%;%JAVA_HOME%
will work, but that's because %JAVA_HOME% is expanded at the command line and PATH is set to the result. If you check the value of PATH, you'll see that it ends with C:\Program Files\Java\jdk1.7.0_25, not %JAVA_HOME%.
将会工作,但这是因为%JAVA_HOME%在命令行中被扩展,并且路径被设置为结果。如果您检查PATH的值,您将看到它以c:programjava\ jdk1.7.0_25结尾,而不是%JAVA_HOME%。
Also, if javac.exe is in the bin subdirectory, you'll need to include that in the path, i.e. add ;C:\Program Files\Java\jdk1.7.0_25\bin
to the path.
同样,如果javac。exe在bin子目录中,您需要将其包括在path中,即add;C:\程序文件\Java\jdk1.7.0_25\bin到路径。
(BTW, you have %JAVA_HOME% in the path twice, and there's an extra semicolon after the second one.)
(顺便说一下,在路径中有%JAVA_HOME%,在第2条后面有一个额外的分号。)
#2
25
Yet another solution is to do this: C:\Program Files
has a short name
另一个解决方案是这样做:C:\Program Files短名称
C:\Progra~1
C:\ Progra ~ 1
in windows.
在windows。
so simply write Progra~1 instead of the Program Files. {added missing 'r'}
所以简单的写程序~1而不是程序文件。{添加失踪' r ' }
#3
2
Is the path you are setting the JAVA_HOME environment variable in a user variable or a system variable? You cannot use user variables within system variables. So if JAVA_HOME is defined as a user variable and you are adding it to your system path that won't work.
在用户变量或系统变量中设置JAVA_HOME环境变量的路径是?不能在系统变量中使用用户变量。因此,如果JAVA_HOME被定义为一个用户变量,并且您将它添加到您的系统路径中,这将不起作用。
From the output of your set command it looks like %JAVA_HOME% is not being resolved. It should show the expanded version not the one with % signs in.
从您的set命令的输出中,看起来%JAVA_HOME%没有得到解决。它应该显示扩展后的版本,而不是有%符号的版本。
Add a Path user variable and add %JAVA_HOME%\bin to that. Windows will add your user path to the end of the system path.
添加路径用户变量,并添加%JAVA_HOME%\bin。Windows将会将您的用户路径添加到系统路径的末端。
You should not need quotes in the JAVA_HOME variable even if it contains spaces.
即使在JAVA_HOME变量中包含空格,也不应该需要引号。
#4
1
Even though Adi Inbar is pretty clear on the problem, I think his workaround isn't the best solution, because it tries to patch around the original problem: spaces in the path of your JDK installation.
尽管Adi Inbar对这个问题非常清楚,但我认为他的解决方案并不是最好的解决方案,因为它试图解决最初的问题:JDK安装路径中的空间。
The best way to solve your problem is actually reinstalling JDK to a space-less path. All other workarounds will cause you headaches in the long run.
解决您的问题的最好方法实际上是将JDK重新安装到无空间的路径上。从长远来看,所有其他的变通方法都会让你头疼。
#5
0
just add cd before adding the location eg: instead of
在添加位置之前添加cd:而不是。
C:\Program Files\Java\jdk1.7.0_25
C:\Program Files\Java\ jdk1.7.0_25
use
使用
cd C:\Program Files\Java\jdk1.7.0_25
cd C:\Program Files\Java\ jdk1.7.0_25
this helped me.
这帮助了我。
#1
21
Okay, that makes it clearer.
好了,这就清楚了。
There are two main problems here.
这里有两个主要问题。
First of all, the reason you're getting 'C:\Program' is not recognized...
is, of course, because it contains spaces. The fact that you have it quoted in the PATH environment variable has no relation to how %JAVA_HOME% is interpreted at the prompt. You have two options.
首先,你得到“C:\程序”的原因是不被认可的……当然,因为它包含空格。在PATH环境变量中引用的事实与如何在提示符中解释%JAVA_HOME%是没有关系的。你有两个选择。
- Quote it when you define the variable, i.e. set JAVA_HOME to
"C:\Program Files\Java\jdk1.7.0_25"
- 当您定义变量时引用它,例如将JAVA_HOME设置为“C:\程序文件\Java\jdk1.7.0_25”
- Quote it when you invoke it. Type
"%JAVA_HOME%\bin"
at the prompt. Of course, you'll get the "not recognized as an internal or external command, operable program or batch file" error unless you end the path with an executable (e.g."%JAVA_HOME%\bin\javac.exe"
), but you'll see that this way it complains about '"C:\Program Files\Java\jdk1.7.0_25"' rather than 'C:\Program'. - 当你调用它时引用它。在提示符处键入“%JAVA_HOME%\bin”。当然,您将获得“不被识别为内部或外部命令、可操作程序或批处理文件”的错误,除非您以可执行程序结束该路径(例如:“%JAVA_HOME%\bin\javac.exe”,但是您会看到这种方式会抱怨“C:\程序文件\Java\jdk1.7.0_25”,而不是“C:\程序”。
Second, you can't use environment variables in the path. You can use environment variables when you set the path at the command prompt. For example,
其次,您不能在路径中使用环境变量。当您在命令提示符中设置路径时,您可以使用环境变量。例如,
set PATH=%PATH%;%JAVA_HOME%
will work, but that's because %JAVA_HOME% is expanded at the command line and PATH is set to the result. If you check the value of PATH, you'll see that it ends with C:\Program Files\Java\jdk1.7.0_25, not %JAVA_HOME%.
将会工作,但这是因为%JAVA_HOME%在命令行中被扩展,并且路径被设置为结果。如果您检查PATH的值,您将看到它以c:programjava\ jdk1.7.0_25结尾,而不是%JAVA_HOME%。
Also, if javac.exe is in the bin subdirectory, you'll need to include that in the path, i.e. add ;C:\Program Files\Java\jdk1.7.0_25\bin
to the path.
同样,如果javac。exe在bin子目录中,您需要将其包括在path中,即add;C:\程序文件\Java\jdk1.7.0_25\bin到路径。
(BTW, you have %JAVA_HOME% in the path twice, and there's an extra semicolon after the second one.)
(顺便说一下,在路径中有%JAVA_HOME%,在第2条后面有一个额外的分号。)
#2
25
Yet another solution is to do this: C:\Program Files
has a short name
另一个解决方案是这样做:C:\Program Files短名称
C:\Progra~1
C:\ Progra ~ 1
in windows.
在windows。
so simply write Progra~1 instead of the Program Files. {added missing 'r'}
所以简单的写程序~1而不是程序文件。{添加失踪' r ' }
#3
2
Is the path you are setting the JAVA_HOME environment variable in a user variable or a system variable? You cannot use user variables within system variables. So if JAVA_HOME is defined as a user variable and you are adding it to your system path that won't work.
在用户变量或系统变量中设置JAVA_HOME环境变量的路径是?不能在系统变量中使用用户变量。因此,如果JAVA_HOME被定义为一个用户变量,并且您将它添加到您的系统路径中,这将不起作用。
From the output of your set command it looks like %JAVA_HOME% is not being resolved. It should show the expanded version not the one with % signs in.
从您的set命令的输出中,看起来%JAVA_HOME%没有得到解决。它应该显示扩展后的版本,而不是有%符号的版本。
Add a Path user variable and add %JAVA_HOME%\bin to that. Windows will add your user path to the end of the system path.
添加路径用户变量,并添加%JAVA_HOME%\bin。Windows将会将您的用户路径添加到系统路径的末端。
You should not need quotes in the JAVA_HOME variable even if it contains spaces.
即使在JAVA_HOME变量中包含空格,也不应该需要引号。
#4
1
Even though Adi Inbar is pretty clear on the problem, I think his workaround isn't the best solution, because it tries to patch around the original problem: spaces in the path of your JDK installation.
尽管Adi Inbar对这个问题非常清楚,但我认为他的解决方案并不是最好的解决方案,因为它试图解决最初的问题:JDK安装路径中的空间。
The best way to solve your problem is actually reinstalling JDK to a space-less path. All other workarounds will cause you headaches in the long run.
解决您的问题的最好方法实际上是将JDK重新安装到无空间的路径上。从长远来看,所有其他的变通方法都会让你头疼。
#5
0
just add cd before adding the location eg: instead of
在添加位置之前添加cd:而不是。
C:\Program Files\Java\jdk1.7.0_25
C:\Program Files\Java\ jdk1.7.0_25
use
使用
cd C:\Program Files\Java\jdk1.7.0_25
cd C:\Program Files\Java\ jdk1.7.0_25
this helped me.
这帮助了我。