Windows 7 环境变量在路径中不起作用

发布于 2024-12-23 08:07:00 字数 273 浏览 1 评论 0原文

我正在尝试使用环境变量设置一些路径。 我添加了一个环境变量“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

打小就很酷 2024-12-30 08:07:00

检查上一个路径和下一个路径之间是否有空格字符:

错误:
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\

世界和平 2024-12-30 08:07:00

我遇到了完全相同的问题,要解决它,您可以执行以下两种操作之一:

  • 将所有变量放入系统变量而不是用户变量中,然后添加您想要的变量 PATH

  • 将所有变量放入用户变量中,然后创建或编辑 PATH用户变量中的变量,而不是系统中的变量。系统中的路径变量不会扩展用户变量。

如果以上都正确,但问题仍然存在,则需要检查系统注册表,在 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:

  • Put all variables in System Variables instead of User and add the ones you want to PATH

Or

  • Put all variables in User Variables, and create or edit the PATH variables in User Variable, not In System. The Path variables in System don't expand the User Variables.

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).

述情 2024-12-30 08:07:00

我的问题变得非常简单:

重新启动命令提示符,新变量应该更新

My issue turned out to be embarrassingly simple:

Restart command prompt and the new variables should update

沐歌 2024-12-30 08:07:00

诸如 %PATH% 或路径中项目之间的空格之类的事情会破坏它。请注意。

是的,包含空格的 Windows 路径会导致错误。例如,应用程序将其添加到系统%PATH%变量定义的前面:

C:\Program Files (x86)\WebEx\Productivity Tools;C:\Sybase\IQ-16_0\Bin64;

这导致%PATH%中的所有路径无法在cmd窗口中设置。

我的解决方案是在需要的地方用双引号来界定扩展路径变量:

"C:\Program Files (x86)\WebEx\Productivity Tools";C:\Sybase\IQ-16_0\Bin64;

因此空格将被忽略,完整路径变量将被正确解析。

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:

C:\Program Files (x86)\WebEx\Productivity Tools;C:\Sybase\IQ-16_0\Bin64;

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:

"C:\Program Files (x86)\WebEx\Productivity Tools";C:\Sybase\IQ-16_0\Bin64;

The spaces are therefore ignored and the full path variable is parsed properly.

飘然心甜 2024-12-30 08:07:00

%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.

吹梦到西洲 2024-12-30 08:07:00

如果 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

别想她 2024-12-30 08:07:00

还值得确保您以管理员身份使用命令提示符 - 我的工作计算机上的系统锁定意味着在键入时无法找到刚刚报告的标准 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'.

笨死的猪 2024-12-30 08:07:00

为了解决这个问题,我使用了 setx 命令来尝试设置用户级变量。

我在下面使用...

setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_92"

setx PATH %JAVA_HOME%\bin

注意: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...

setx JAVA_HOME "C:\Program Files\Java\jdk1.8.0_92"

setx PATH %JAVA_HOME%\bin

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%

浅紫色的梦幻 2024-12-30 08:07:00

如果在将用户的 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%".

羁拥 2024-12-30 08:07:00

我在 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.

柒七 2024-12-30 08:07:00

在我的 Windows 7 中。

// not working for me
D:\php\php-7.2.6-nts\php.exe

// works fine
D:\php\php-7.2.6-nts

In my Windows 7.

// not working for me
D:\php\php-7.2.6-nts\php.exe

// works fine
D:\php\php-7.2.6-nts
逆夏时光 2024-12-30 08:07:00

我遇到了同样的问题,我通过从用户变量中删除 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

黄昏下泛黄的笔记 2024-12-30 08:07:00

将路径的值复制到记事本并检查这是否与终端窗口中的 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.

放低过去 2024-12-30 08:07:00

确保您的系统路径和用户路径设置正确。

Make sure both your System and User paths are set correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文