回声 %JAVA_HOME% 返回 %JAVA_HOME%
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51243045/
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
echo %JAVA_HOME% returns %JAVA_HOME%
提问by gaming with yoty
When I do
当我做
echo %JAVA_HOME%
it returns %JAVA_HOME%
on windows 10 what did I do wrong?
它%JAVA_HOME%
在 Windows 10 上返回我做错了什么?
回答by Matsemann
The syntax depends on the shell/terminal you are using. Try
语法取决于您使用的外壳程序/终端。尝试
echo $JAVA_HOME
this is the syntax for bash, for instance if you are using Git Bash to run your commands.
这是 bash 的语法,例如,如果您使用 Git Bash 来运行您的命令。
回答by SleepyX667
I'm not sure, but i thought you need $ for Environment Variables.
我不确定,但我认为环境变量需要 $ 。
Try: echo $JAVA_HOME
尝试: echo $JAVA_HOME
回答by JWo
Your command is correct for a windows 10 machine. And the result tells us, that this variable is not set. You can look for the settings for the environment variables in your start menu. You'll see settings for other variables like Path, TEMP and so on. There you can add JAVA_HOME (here without %). The path would be like this (from my pc): C:\Program Files\Java\jdk1.8.0_161
您的命令对于 Windows 10 机器是正确的。结果告诉我们,这个变量没有设置。您可以在开始菜单中查找环境变量的设置。您将看到其他变量的设置,例如 Path、TEMP 等。在那里你可以添加 JAVA_HOME(这里没有 %)。路径是这样的(来自我的电脑):C:\Program Files\Java\jdk1.8.0_161
回答by Rafa? Sokalski
It prints "JAVA_HOME" because you didn't set JAVA_HOME variable or you have typo in variable name. Just go to your environment variables settings and check if it's correct. If you don't have JAVA_HOME there just look at this question: How to set JAVA_HOME
它打印“JAVA_HOME”,因为您没有设置 JAVA_HOME 变量或变量名称中有错字。只需转到您的环境变量设置并检查它是否正确。如果你没有 JAVA_HOME 就看看这个问题:How to set JAVA_HOME
回答by davidalayachew
I know this answer is well overdue, but after hours of searching, it solved the problem for me.
我知道这个答案早就应该了,但经过数小时的搜索,它为我解决了问题。
Reinstall everything (git, jdk/jre, potentially maven), but when you do, leave EVERYTHING as its default value. Do not change any of the settings, DO NOT CHOOSE A SPECIFIC SAVE LOCATION that is convenient for you, etc. Leave everything as their default values.
重新安装所有东西(git、jdk/jre,可能是 maven),但是当你这样做的时候,把 EVERYTHING 作为它的默认值。不要更改任何设置,不要选择方便您的特定保存位置等。将所有内容保留为默认值。
Turns out, git is particularly rigid when it comes to flexibility, and it doesn't play well if you change the install location. When I was installing git, I changed the save location. I had been installing and practicing a bunch of new tools, and I wanted to have them all in one isolated spot. Just goes to show that the default way is usually the best way.
事实证明,git 在灵活性方面特别僵化,如果您更改安装位置,它就不能很好地发挥作用。当我安装git时,我更改了保存位置。我一直在安装和练习一堆新工具,我想把它们都放在一个孤立的地方。只是表明默认方式通常是最好的方式。
回答by sr56
If you are sure that you have set them properly, you can print your environment variables like JAVA_HOME using any of the below methods in Windows 10.
如果您确定已正确设置它们,则可以在 Windows 10 中使用以下任何方法打印环境变量,例如 JAVA_HOME。
Windows Command prompt ( cmd.exe )
C:\>echo %JAVA_HOME% C:\Program Files\Java\jdk1.7.0_80
Windows 命令提示符 ( cmd.exe )
C:\>echo %JAVA_HOME% C:\Program Files\Java\jdk1.7.0_80
Git Bash within windows, you need to use the bash format
user12231@TP-UN103 MINGW64 /c $ echo $JAVA_HOME C:\Program Files\Java\jdk1.7.0_80
windows内的Git Bash,需要使用bash格式
user12231@TP-UN103 MINGW64 /c $ echo $JAVA_HOME C:\Program Files\Java\jdk1.7.0_80
From the conversation, it looks like you are using Windows 10 powershell.
To print the environment variable in windows powershell, use one of the following commands as belowPS C:\>Get-ChildItem Env:JAVA_HOME Name Value ---- ----- JAVA_HOME C:\Program Files\Java\jdk1.7.0_80
or
PS C:\> echo $env:JAVA_HOME C:\Program Files\Java\jdk1.7.0_80
You can refer the Powershell documentation here.
从对话来看,您似乎正在使用 Windows 10 powershell。
要在 windows powershell 中打印环境变量,请使用以下命令之一,如下所示PS C:\>Get-ChildItem Env:JAVA_HOME Name Value ---- ----- JAVA_HOME C:\Program Files\Java\jdk1.7.0_80
或者
PS C:\> echo $env:JAVA_HOME C:\Program Files\Java\jdk1.7.0_80
您可以在此处参考 Powershell 文档。
回答by Frostbyte1010
There is high possibility that you used the windows 10 powershellterminal unknowingly instead of the standard windows command prompt.
您很有可能在不知不觉中使用了 windows 10 powershell终端,而不是标准的 windows 命令提示符。
In a standard Windows command prompt you would type,
在标准的 Windows 命令提示符下,您将键入:
echo %JAVA_HOME%
But in powershell you would see JAVA_HOMEwritten out.
但是在 powershell 中,您会看到JAVA_HOME写出。
Powershell does things differently. In this case to output environment variables you need to use
Powershell 以不同的方式做事。在这种情况下输出您需要使用的环境变量
echo $Env:JAVA_HOME
回答by Kiki Risager
If you just added the System Variable you need to reboot for System to read it
如果您刚刚添加了系统变量,则需要重新启动系统才能读取它
if you are using an classic cmd command "echo %JAVA_HOME%" in windowsJAVA is fine
如果您在 windowsJAVA 中使用经典的 cmd 命令“echo %JAVA_HOME%”就可以了