I'm trying to compile using javac in the windows console (cmd), but if I type javac
it tells me:
"javac" is not recognized as an external or internal command
Same thing happened to me with pip in python and never fixed it.
Add the path in different ways but none works. Then, I tried to compile manually and if it worked, that is:
C:\directorio\del\archivo\a\compilar>nombre del archivo C:\directorio\del\javac
First of all, I recommend you to create the JAVA_HOME variable in your work environment. For this, go to System Properties, Environment Variables and register the following variable:
Value example: C:\Program Files\Java\jdk1.8.0_131 (do it without the
\
at the end)Next, you need to edit the system PATH variable (very carefully) and add the following to the start of it :
Accept the changes made, close all your command lines (CMD) that you have open. Now, open a new one and enter
javac -version
. The output should correspond to the version you have of the JDKExample (in my windows cmd)
For
pip
is similar. You must edit the PATH variable and, at the beginning, add the path of the folder where thepip
. OK, close all terminals, reopen cmd and runpip
.After installing the JDK, you can compile Java classes by telling the system the absolute path to javac , as you say, manually, since the system does not have the path registered for this command:
This instruction allows the system to find both the file to compile and the command to use and can be shortened if we open the terminal (cmd) in the directory where the file to compile is.
You can't just use the javac command , because you need to tell the system where to find it (which you do with the above command). We must add the path in the Environment Variables , generally in those of our user. To do it and in a general way we are going to:
This opens the System Properties window , clicking the "Environment Variables..." button will open a new window like this:
At the top you have the variables for the current user. The normal thing will be to add your path in the PATH variable , if it does not exist we create it (New...), otherwise we add the path to javac to the list of already existing paths, either with a double click on the PATH row or or by selecting it and pressing "Edit...". This opens a new window to add/modify the values of the variable.
Example:
Added the desired route, click "OK" in the three pop-up windows that we have open and close the System Options window that we opened from the Control Panel .
To verify that the javac command is available and works correctly, open a console (if we had it open, close it so that it can recognize the new configuration) and write:
If we did everything right, it will return a message indicating the installed version: