How can I set the PATH variable for javac so I can manually compile my .java works?
Solution 1:
That would be:
set "PATH=%PATH%;C:\Program Files\Java\jdk1.6.0_18\bin"
You can also append ;C:\Program Files\Java\jdk1.6.0_18\bin
to the PATH in the user environment dialog. That would allow you to use javac and other java tools directly form any cmd shell without setting the path first. The user environment dialog used to be somewhere in the system properties in XP, I have no idea where it is in Windows 7.
Solution 2:
Typing the SET PATH
command into the command shell every time you fire it up could get old for you pretty fast. Three alternatives:
- Run javac from a batch (
.CMD
) file. Then you can just put theSET PATH
into that file before yourjavac
execution. Or you could do without theSET PATH
if you simply code the explicit path tojavac.exe
- Set your enhanced, improved
PATH
in the "environment variables" configuration of your system. - In the long run you'll want to automate your Java compiling with Ant. But that will require yet another extension to
PATH
first, which brings us back to (1) and (2).
Solution 3:
Step 1: Set the PATH variable JAVA_HOME to the path of the JDK present on the system. Step 2: in the Path variable add the path of the C:\Program Files\Java\jdk(version)\bin
This should solve the problem. Happy coding!!