简体   繁体   中英

Javac not recognised even after setting variable path, Windows 10?

I'm getting an error when typing javac in command prompt.

C:\Users\HP>javac

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

C:\Users\HP>set path
path=C:\Program Files\Java\jdk-10\bin;C:\Program Files\Java\jre-10\bin\javaw.exe;C:\Program Files\Java\jdk-10\bin;C:\Program Files\Java\jre-10\bin;
PATHEXT=C:\Program Files (x86)\Documents;

I have already set Path in both system and user scope environment varible?

You may set 2 system variable from console:

set JAVA_HOME="c:\Program Files\Java\jdk1.8.0_144"
set PATH=%JAVA_HOME%\bin;%PATH%

then your command "javac" will be found.

The PATH variable looks corrupted. Moreover, the PATHEXT variable is totally confused. Their default value in Windows 7/10/2008 (assuming the system drive is C: ) should be as follows:

PATH    C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem;{plus program paths}
PATHEXT .COM; .EXE; .BAT; .CMD; .VBS; .VBE; .JS ; .WSF; .WSH; .MSC

Check output from SET PATH in a freshly open cmd window. If path and pathext look as above then use (modify directory names to match current Java version):

set "JAVA_HOME=C:\Program Files\Java\jre-9.0.4"
set "PATH=%JAVA_HOME%\bin;%PATH%"

Above setting is temporary (would last only for current cmd session). For persistent solution, there are more tutorials on the net eg How To Set Java Path & Java Home Variables (Windows, MacOS, Ubuntu) .

Try out the following solutions.

  1. Close your current cmd and Open a new cmd.exe
  2. Restart the computer

NOTE: If cmd is open when you set the environment variables, then, that property will not be available until unless you open new cmd .

On Windows 10, the problem of 'javac is not recognized ...' can be fixed in these 4 steps:

Step 1: Install JDK to specific path (Example: C:\\jdk-15)

Step 2: Setup JAVA_HOME environment variable to the installation folder

   Windows --> Advanced settings --> Environment variables --> System Variable 
   
   --> Add new variable  

   JAVA_HOME  =  C:\jdk-15

Step 3: Prefix JAVA_HOME\\bin to PATH variable of Windows

 Windows --> Advanced settings --> Environment variables --> System Variables 

 --> Update PATH variable


 PATH =  JAVA_HOME\bin;..... old value of PATH variable .... 

Step 4: Try the javac and java commands in new command window

Note: Already opened command windows will not take the new values of JAVA_HOME or PATH. The test needs to be done in new window opened after the environment variables are changed and saved.

C:\Users\user1> javac -version

C:\Users\user1> java -version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM