How can I set the PATH variable for javac so I can manually compile my .java works?
Here's the address on开发者_Go百科 my drive:
C:\Program Files\Java\jdk1.6.0_18\bin
How would I go about setting the path variable so I can go in command window (windowskey+r "cmd") and be able to type things like:
javac TestApp.java
I'm using Windows 7 Professional.
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.
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).
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!!
- Type
cmd
in program start - Copy and Paste following on dos prompt
set PATH="%PATH%;C:\Program Files\Java\jdk1.6.0_18\bin"
Follow the steps given here
http://www.javaandme.com/
after setting variable, just navigate to your java file directory in your cmd and type javac "xyx.java"
or if you don't navigate to the directory, then simply specify the full path of java file
javac "/xyz.java"
First thing I wann ans to this imp question: "Why we require PATH To be set?"
Answer : You need to set PATH to compile Java source code, create JAVA CLASS FILES and allow Operating System to load classes at runtime.
Now you will understand why after setting "javac" you can manually compile by just saying "Class_name.java"
Modify the PATH of Windows Environmental Variable by appending the location till bin directory where all exe file(for eg. java,javac) are present.
Example : ;C:\Program Files\Java\jre7\bin.
only this will work:
path=%set path%;C:\Program Files\Java\jdk1.7.0_04\bin
You don't need to do any complex command-line stuff or edit any system code. You simply have to open Computer, showing all of your disks and open properties. From there, go to Advanced System Settings and click Environment Variables. Scroll down in the lower list box and edit Path. Do not erase anything already there. Put a ; after it and then type in your path. To test, open command prompt and do "javac", it should list around 20 programs. You would be finished at that point.
By the way, the command to compile is javac -g
not just javac
.
Happy coding!
Trying this out on Windows 10, none of the command-line instructions worked.
Right clicking on "Computer" then open Properties etc. as the post by Galen Nare above already explains, leads you to a window where you need to click on "new" and then paste the path (as said: without deleting anything else). Afterwards you can check by typing java -version in the command-line window, which should display your current java version, if everything worked out right.
精彩评论