Windows 7 环境变量在路径中不起作用
我正在尝试使用环境变量设置一些路径。 我添加了一个环境变量“MAVEN_HOME”,其值为“C:\maven”。 然后在路径中我添加了“%MAVEN_HOME%\bin;...rest”。 当我输入“echo $MAVEN_HOME%”时,我会在屏幕上打印出正确的“C:\maven”。 但是当我输入“bin”目录中的批处理文件“mvn”时,它找不到它。
所以,我手动将整个路径添加到PATH中。 “C:\maven\bin;...休息” 它能够找到“mvn”并执行它。
有人可以帮助我做错了什么吗?
I am trying to set up some path using environment variable.
I added an environment variable "MAVEN_HOME" with the value "C:\maven".
Then in the path I added "%MAVEN_HOME%\bin;...rest".
When I type "echo $MAVEN_HOME%" I get the correct "C:\maven" printed on the screen.
But when I type "mvn" which is a batch file in the "bin" directory, it can't find it.
So, I manually added the entire path in PATH.
"C:\maven\bin;...rest"
and it was able to find "mvn" and execute it.
Could someone help me what I did wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
检查上一个路径和下一个路径之间是否有空格字符:
错误:
c:\path1; c:\Maven\bin\; c:\path2\
正确:
c:\path1;c:\Maven\bin\;c:\path2\
Check if there is a space character between the previous path and the next:
Incorrect:
c:\path1; c:\Maven\bin\; c:\path2\
Correct:
c:\path1;c:\Maven\bin\;c:\path2\
我遇到了完全相同的问题,要解决它,您可以执行以下两种操作之一:
或
如果以上都正确,但问题仍然存在,则需要检查系统注册表,在 HKEY_CURRENT_USER\Environment 中,确保“PATH”键类型为 REG_EXPAND_SZ(而不是 REG_SZ)。
I had exactly the same problem, to solve it, you can do one of two things:
Or
If the above are all correct, but the problem is still present, you need to check the system Registry, in HKEY_CURRENT_USER\Environment, to make sure the "PATH" key type is REG_EXPAND_SZ (not REG_SZ).
我的问题变得非常简单:
重新启动命令提示符,新变量应该更新
My issue turned out to be embarrassingly simple:
Restart command prompt and the new variables should update
诸如 %PATH% 或路径中项目之间的空格之类的事情会破坏它。请注意。
是的,包含空格的 Windows 路径会导致错误。例如,应用程序将其添加到系统%PATH%变量定义的前面:
这导致%PATH%中的所有路径无法在cmd窗口中设置。
我的解决方案是在需要的地方用双引号来界定扩展路径变量:
因此空格将被忽略,完整路径变量将被正确解析。
Things like having %PATH% or spaces between items in your path will break it. Be warned.
Yes, windows paths that include spaces will cause errors. For example an application added this to the front of the system %PATH% variable definition:
which caused all of the paths in %PATH% to not be set in the cmd window.
My solution is to demarcate the extended path variable in double quotes where needed:
The spaces are therefore ignored and the full path variable is parsed properly.
%M2% 和 %JAVA_HOME% 需要添加到 USER 变量中的 PATH 变量中,而不是 SYSTEM 变量中。
%M2% and %JAVA_HOME% need to be added to a PATH variable in the USER variables, not the SYSTEM variables.
如果 PATH 中有任何错误,窗口将默默地忽略它。诸如 %PATH% 或路径中项目之间的空格之类的事情会破坏它。请注意
If there is any error at all in the PATH windows will silently disregard it. Things like having %PATH% or spaces between items in your path will break it. Be warned
还值得确保您以管理员身份使用命令提示符 - 我的工作计算机上的系统锁定意味着在键入时无法找到刚刚报告的标准 cmd mvn
mvn --version
要使用,请单击“开始>”所有程序>附件”,右键单击“命令提示符”并选择“以管理员身份运行”。
Also worth making sure you're using the command prompt as an administrator - the system lock on my work machine meant that the standard cmd just reported mvn could not be found when typing
mvn --version
To use click 'start > all programs > accessories', right-click on 'command prompt' and select 'run as administrator'.
为了解决这个问题,我使用了 setx 命令来尝试设置用户级变量。
我在下面使用...
注意:Windows 尝试将提供的变量值附加到现有变量值。所以不需要提供额外的 %PATH%...类似 %JAVA_HOME%\bin;%PATH%
To address this problem, I have used setx command which try to set user level variables.
I used below...
NOTE: Windows try to append provided variable value to existing variable value. So no need to give extra %PATH%... something like %JAVA_HOME%\bin;%PATH%
如果在将用户的 PATH 变量连接到环境 PATH 变量后 PATH 值太长,Windows 将无法连接用户 PATH 变量。
在安装新软件并向 PATH 中添加某些内容后,很容易发生这种情况,从而破坏现有已安装的软件。 Windows 失败!
最好的解决方法是编辑控制面板中的 PATH 变量之一并删除不需要的条目。然后打开一个新的 CMD 窗口,查看所有条目是否都显示在“echo %PATH%”中。
If the PATH value would be too long after your user's PATH variable has been concatenated onto the environment PATH variable, Windows will silently fail to concatenate the user PATH variable.
This can easily happen after new software is installed and adds something to PATH, thereby breaking existing installed software. Windows fail!
The best fix is to edit one of the PATH variables in the Control Panel and remove entries you don't need. Then open a new CMD window and see if all entries are shown in "echo %PATH%".
我在 Windows 10 中遇到了这个问题,在我关闭任务管理器中的“explorer.exe”后,它似乎得到了解决。
I had this problem in Windows 10 and it seemed to be solved after I closed "explorer.exe" in the Task Manager.
在我的 Windows 7 中。
In my Windows 7.
我遇到了同样的问题,我通过从用户变量中删除 PATHEXT 来修复它。它只能存在于系统变量中 .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
也将变量从用户删除到系统,并且仅将该路径包含在用户变量中
I had the same problem, I fixed it by removing PATHEXT from user variable. It must only exist in System variable with .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
Also remove the variable from user to system and only include that path on user variable
将路径的值复制到记事本并检查这是否与终端窗口中的 echo %path% 相对应,并根据需要进行更改。然后删除旧的路径值并将记事本值粘贴回来。
我假设某些安装输入的一些不可见字符损坏了路径值。
Copy the value of path to notepad and check if this corresponds with the echo %path% in terminal window and make changes if needed. Then delete the old path value and paste the notepad value back in.
I assume some invisible character entered there by some installation corrupted the path value.
确保您的系统路径和用户路径设置正确。
Make sure both your System and User paths are set correctly.