javac not working in windows command prompt

2019-01-03 22:19发布

I'm trying to use javac with the windows command prompt, but it's not working.

After adding the directory "C:\Program Files\Java\jdk1.6.0_16\bin\" to the end of the PATH environment variable, the java command works fine, but using javac gives me the following error:

'javac' is not recognized as an internal or external command, operable program or batch file.

17条回答
forever°为你锁心
2楼-- · 2019-01-03 22:49

I just had to do this to get this to work on windows 7 64.

Open up a command prompt (cmd.exe) and type:

set CLASSPATH=C:\Program Files\Java\jdk1.7.0_01\bin

Make sure you reopen all running command prompt Windows to get the environment variable updated as well.

查看更多
【Aperson】
3楼-- · 2019-01-03 22:50

";C:\Program Files\Java\jdk1.6.0\bin" sometime you may forget to put semicolon on last existing path.

查看更多
叼着烟拽天下
4楼-- · 2019-01-03 22:51

If you added it in the control panel while your command prompt was open, that won't affect your current command prompt. You'll need to exit and re-open or simply do:

set "path=%path%;c:\program files\java\jdk1.6.0_16\bin"

By way of checking, execute:

echo %path%

from your command prompt and let us know what it is.

Otherwise, make sure there is a javac in that directory by trying:

"c:\program files\java\jdk1.6.0_16\bin\javac.exe"

from the command prompt. You can also tell which executable (if any) is being used with the command:

for %i in (javac.exe) do @echo %~$PATH:i

This is a neat trick similar to the which and/or whence commands in some UNIX-type operating systems.

查看更多
ら.Afraid
5楼-- · 2019-01-03 22:52

I know this may not be your specific error, but I once had a leading space in my path and java would work but javac would not.

For what it's worth, I offer the sage advice: "Examine your Path closely".

查看更多
小情绪 Triste *
6楼-- · 2019-01-03 22:53

Ensure you don't allow spaces (white space) in between paths in the Path variable. My problem was I had white space in and I believe Windows treated it as a NULL and didn't read my path in for Java.

查看更多
贼婆χ
7楼-- · 2019-01-03 22:56

I faced the exact same problem that java would work but javac would not on a cmd prompt in Windows 8.

The problem occured because I forgot to remove '>' at the end of the path name, i.e., it was like this:

C:\Program Files\Java\jdk*\bin>

where it was suppose to be like this:

C:\Program Files\Java\jdk*\bin
查看更多
登录 后发表回答