It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Javac Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Javac" Watch "Javac" New topic
Author

Javac

Sky Mendoza
Greenhorn

Joined: Jan 11, 2013
Posts: 9
Im just starting as a programmer. When im at school, i can compile at java. But when i try to compile a program at home, it says javac is not recognized as an internal or external command error. I really dont know what to do. I tried changing the environment settings but still, nothing happened. What should i do?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3487
    
  13
Have you installed the JDK ?


Joanne
Sky Mendoza
Greenhorn

Joined: Jan 11, 2013
Posts: 9
Yep. I installed JDK 1.7
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3487
    
  13
In that case you haven't set up the PATH environment variable properly.
If you are running Windows open a command prompt and type
echo %PATH%
and make sure that the bin directory of your JDK installation is included
Sky Mendoza
Greenhorn

Joined: Jan 11, 2013
Posts: 9
It says C:\Windows\system32 is not recognized as an internal or external command, operable program or batch file.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
Why are you trying to pass the name of a directory as a command?
Read our FAQ, which tells you how to set the PATH. There are other ways to set the PATH than what we describe.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3487
    
  13
Sky Mendoza wrote:It says C:\Windows\system32 is not recognized as an internal or external command, operable program or batch file.

Did you type
echo %PATH%
or just
%PATH%
Sky Mendoza
Greenhorn

Joined: Jan 11, 2013
Posts: 9
Oh sorry. I just typed %PATH% but i tried echo %PATH% and this is C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShel l\v1.0\;C:\Program Files (x86)\Java\jdk1.7.0_10\bin
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3487
    
  13
That looks okay.
Try typing
"C:\Program Files (x86)\Java\jdk1.7.0_10\bin\javac"
in the command prompt. Be sure to include the quotes as there are spaces in the directory name

Sky Mendoza
Greenhorn

Joined: Jan 11, 2013
Posts: 9
A long post appeared. I tried running my program but still it says javac is not recognized blah blah.



And btw, what should be the variable value in the Path?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3487
    
  13
Sky Mendoza wrote:A long post appeared. I tried running my program but still it says javac is not recognized blah blah.

I'm stumped then I'm afraid. If it works when you type the full path name, then it should work when you type javac.
Maybe someone else will see this post and have some other suggestions.

As a workaround you could try creating a batch file that includes the full path to the javac command and use that for compiling your program.

Sky Mendoza wrote:And btw, what should be the variable value in the Path?

I'm not sure what you are asking. The value of your PATH variable looks okay as it is.
Andy Jack
Ranch Hand

Joined: Nov 22, 2012
Posts: 257
If you want to begin coding right away for some reason, then try this -

If you have a windows pc, then set the 'path' variable to point to javac.exe. 'Path' is located in 'environment' variables in 'my computer'. A long time ago i read that this method has some disadvantages. But, at least you can begin working right away.
When you have more time on hand, reset the path and try command line.

google 'setting path environment variable windows' for detailed instructions.




Java Newbie with 72% in OCJP/SCJP - Super Confused Jobless Programmer.
I am a "newbie" too. Please verify my answers before you accept them.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3487
    
  13
Andy Jack wrote:If you have a windows pc, then set the 'path' variable to point to javac.exe.

No. It should point to the directory that javac.exe is in, not javac.exe itself. And if you look at the PATH that Sky posted earlier you will see that it already does this.

Andy Jack wrote:A long time ago i read that this method has some disadvantages. But, at least you can begin working right away.

As long as you add the directory to the PATH variable (rather than overwriting anything that is already in the PATH), then this is the correct way to do it.
Sky Mendoza
Greenhorn

Joined: Jan 11, 2013
Posts: 9
This is the variable value of my Path in the environment %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShel l\v1.0\;C:\Program Files (x86)\Java\jdk1.7.0_10\bin

I dont know if this is correct.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Is the JDK really installed in the directory C:\Program Files (x86)\Java\jdk1.7.0_10 or did you install it somewhere else? Check with Windows Explorer if that directory exists.

If the JDK is installed somewhere else, then make the PATH point to the correct directory.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 867
    
    5
A sidenote.
I do not put the Java bin directory to PATH but put wrapping scripts to the PATH like javac16, java16, javap16, javac17, java17, javap17 etc.
They invoke javac, java, javap directly with the full path names.

Thus several versions coexist peacefully on the same box.
Divya Chandel
Ranch Hand

Joined: Jun 09, 2011
Posts: 46


First locate where java is installed, and where javac.exe is located.
This will probably be something along the lines of C:\jdk\bin\ or C:\Program Files\Java\jdk\bin\

Second, go to Windows Explorer, right click My Computer, go to Properties, the Advanced tab, Environmental Variables.
Under System variables, look for Path. Do NOT remove anything here, but at the END add a semicolon (;) and put path till C:\Program Files\Java\jdk\bin\

Remember put correct folder name.



Divya
SCJP1.6
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
Divya Chandel wrote: . . . Do NOT remove anything here, but at the END add a semicolon (;) and put path till C:\Program Files\Java\jdk\bin\ . . .
That is incorrect. The path to the new Java installation belongs at the beginning of the PATH.
You should remove old Java installation folders from the PATH.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javac