aspose file tools*
The moose likes Beginning Java and the fly likes Running Java Command LIne Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Running Java Command LIne" Watch "Running Java Command LIne" New topic
Author

Running Java Command LIne

Mark Nibert
Ranch Hand

Joined: Jul 01, 2009
Posts: 42
Ok so I posted earlier and maybe I am missing something w/ running a java program from the command line. Here is the path I have in the command line "C:\Program Files (x86)\Java\jdk1.6.0_14\bin"
Where do I save the .java files, I have read through a couple tutorials and maybe I just dont get it. I appreciate any help as I have searched and searched and cannot seem to get it.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You put the .java (the source code files) in a package/directory hierarchy, wherever you want.
Mark Nibert
Ranch Hand

Joined: Jul 01, 2009
Posts: 42
I think that is where I am confused when I run javac <programname> and I am in the bin file how does it know where the compiler is? I am not following how to do it at all.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

You put the .java (the source code files) in a package/directory hierarchy, wherever you want

I would not recommend to put them under C:\Program Files (x86)\Java\jdk1.6.0_14\bin

I suggest you to make a new directory somewhere. For example, C:\java\src. If your source is in a package, make new directories under C:\java\src. For example :

You would put this class here : C:\java\src\sample\MarkNibert.java


[My Blog]
All roads lead to JavaRanch
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

how does it know where the compiler is?

I see your are using Windows. Windows uses special environment variables to hold certain information. There's one called PATH. It holds directories. If you type a command at the command line, these directories will be scanned to find the command. Try to type SET at the command line. You'll see PATH in the list. C:\Program Files (x86)\Java\jdk1.6.0_14\bin must be in there.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Also, a good place to start is here.
Mark Nibert
Ranch Hand

Joined: Jul 01, 2009
Posts: 42
I am feeling pretty retarded. I am not able to get it to work. I created c:\java\src and the folder I have my application in is chap11 so the full path is c:\java\src\chap11 here is the code



When I run the code while in the c:\java\src directory or the c:\java\src\chap11 directory it returns an error

'javac' is not recognized as an internal or external command, operable program or batch file

So I retyped it out w/ the full path to the javac and it still doesnt work. I am on windows 7 and eclipse works so I think I have the right jdk installed.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

'javac' is not recognized as an internal or external command, operable program or batch file

Which means that your sdk bin directory is not in the PATH. Check this page which tells you how to edit the PATH in Vista. Edit it, and add "C:\Program Files (x86)\Java\jdk1.6.0_14\bin". Make it the first directory in the PATH.
Mark Nibert
Ranch Hand

Joined: Jul 01, 2009
Posts: 42
Ok that worked so it knows where the compiler is. It is now working, thanks a million for putting up w/ my ignorance.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39784
    
  28
Lots of people have that problem; setting the PATH is very confusing until you have done it a few times.
Mark Nibert
Ranch Hand

Joined: Jul 01, 2009
Posts: 42
Yeah it seems easy looking back but last night I was ready to rip my hair out. I appreciate the help. I really enjoy these forums, everyone is so helpful. I wish I had the money to do the 200 dollar class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running Java Command LIne