Javac is the executable for compiling java applications. When compiling a java program from command line, this is the most common issue people face. Let’s see how we can fix this issue.
- First thing we need to compile java programs is to have JDK(Java development Kit) installed on your computer. If you are not sure whether you have already installed it or not, you can verify from appwiz.cpl.(More details here – How do I check if Java is installed on my system)
- If java is installed, then you need to check if PATH environment variable points to the java executables directory.
- Open command prompt
- Run ‘set path’. This will print the current value of path environment variable. You can see the list of all the directories added. Check if Java sdk path is added or not. If it’s added you should be able to see something like below.
Path=C:\Program Files (x86)\Windows Resource Kits\Tools\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Quarantine\;C:\Program Files\Perforce;C:\Program Files\Microsoft Network Monitor 3\;c:\Program Files\Java\jdk1.7.0_17\bin
- If you don’t find JDK path you can add now. Please note that the path you need to add on your system would vary based on the SDK version you installed and also the location of the installation. Check the folder “C:\Program Files\java” and “c:\Program Files (x86)\java” to find the exact path.
- You can modify PATH variable from command prompt or from GUI. For command line steps, please see – Set path from windows command prompt
- To modify PATH using GUI you can follow the steps below.
Please note that having JRE is not enough to develop java applications. JRE only helps to run already built applications, we need JDK to compile Java code.
Add java SDK directories to PATH
- Open System properties (Run sysdm.cpl)
- Go to Advanced tab
- Click ‘Environment variables’
- Under ‘System Variables’ scroll down to find PATH. Edit the entry and add JDK path.
- Click OK and close the windows.
Now open new command prompt and run ‘set path’, you can see that JDK path is added. Note that if you run the command from a window which was opened before you modified the PATH variable, it would not print updated path. Even for compiling java programs, you need to open a new command window after setting PATH.