“java -version” not working in command prompt

匿名 (未验证) 提交于 2019-12-03 08:35:02

问题:

I downloaded this Java JDK and installed it.

But when I go to the command prompt to check the version, it says it's not recognized.

Is anyone else experiencing this issue with the latest Java?

I might not have installed the right version. I need the java that works with grails

C:\>java 'java' is not recognized as an internal or external command, operable program or batch file.  C:\>java -version 'java' is not recognized as an internal or external command, operable program or batch file.  C:\> 

when i do a search on my computer for java, it does not find anything

回答1:

Windows 2k8 R2 server- For both java [-option] or %JAVA_HOME% to work in the command line you need the following:

In Control Panel->System and Security->System->Advanced system setting->Advanced->Environment Variables->System Variables

Edit the Path variable and add a ";" after the last value and add the the path to the Java bin directory: e.g.- C:\Progra~2\Java\jre6\bin\

Add the JAVA_HOME Variable with the value set to the path for the java executable: e.g.- C:\Progra~2\Java\jre6\bin\java.exe



回答2:

Java is typically installed (on Windows) as C:\Program Files\Java\jdk<version>

That installation directory has a subdirectory bin which you need to append to your PATH environment variable via the control panel. Then, the commands like java, javac etc. will be available on the command line.

BTW, the same is true for Grails.



回答3:

Is the -version flag not recognized, or is the "java" command not recognized? One way to test this is just to type 'java' by itself and run it and see what happens.

If the command is not recognized, make sure that the JDK's install path is in your windows PATH. If not, you won't be able to use any of the java executables from the command prompt. Here's another link that may help out.



回答4:

For Linux:

check $PATH and $JAVA_HOME. You can configure it in /etc/environment

From console you can check it like:

$ echo $PATH 

For Windows:

My Computer -> Properties -> Advanced -> Environment Variables Check there PATH.

From console you can check it like:

echo %PATH% 


回答5:

Press simultaneously the "windows" and "pause" buttons on your keyboard, this will bring up the System Preferences dialog. In the Advanced tab, find Environment Variables.

Then, in the User (upper) section, create or update the following two variables :

  • JAVA_HOME = where you put your JDK, eg. C:/Java/SDK
  • PATH = %JAVA_HOME%/bin

Close the dialogs.

Then, in a new command-line console, try "javac -version" and see if it's detected. It's important that you use a new console, because environment variables are read only when the console is launched.



回答6:

You need to manually add the path to javac.exe and java.exe to your operating system path. The Java installation program doesn't do that for you.



回答7:

You most likely don't have java.exe in your system's PATH variable.



回答8:

You installed the JDK. Isn't java.exe part of the JRE? Do you have that installed?



回答9:

You should have a Java icon in Windows Control Panel. Locate the Java tab and click the View button. That will show you the path to the Java executables.

Last but not least, make sure you have restarted the computer so changes in the PATH variable can take effect.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!