Sergio Tapia
Sergio Tapia

Reputation: 41208

How can I set the PATH variable for javac so I can manually compile my .java works?

Here's the address on 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.

Upvotes: 20

Views: 171395

Answers (9)

prettyUgly
prettyUgly

Reputation: 1

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.

Upvotes: -1

Carl Smotricz
Carl Smotricz

Reputation: 67820

Typing the SET PATH command into the command shell every time you fire it up could get old for you pretty fast. Three alternatives:

  1. Run javac from a batch (.CMD) file. Then you can just put the SET PATH into that file before your javac execution. Or you could do without the SET PATH if you simply code the explicit path to javac.exe
  2. Set your enhanced, improved PATH in the "environment variables" configuration of your system.
  3. 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).

Upvotes: 17

Pushp Singh
Pushp Singh

Reputation: 606

only this will work:

path=%set path%;C:\Program Files\Java\jdk1.7.0_04\bin

Upvotes: 3

Capcha
Capcha

Reputation: 77

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!!

Upvotes: 7

NishantM
NishantM

Reputation: 121

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.

Upvotes: 2

x4u
x4u

Reputation: 14075

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.

Upvotes: 29

Pratap
Pratap

Reputation: 4727

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"

Upvotes: 2

Galen Nare
Galen Nare

Reputation: 336

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!

Upvotes: 1

RAi
RAi

Reputation: 21

  1. Type cmd in program start
  2. Copy and Paste following on dos prompt

set PATH="%PATH%;C:\Program Files\Java\jdk1.6.0_18\bin"

Upvotes: 2

Related Questions