File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes cannot execute java command from command prompt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cannot execute java command from command prompt" Watch "cannot execute java command from command prompt" New topic

cannot execute java command from command prompt

sarim raza
Ranch Hand

Joined: Nov 02, 2000
Posts: 232

the directory is right, thats where my .java file is
the javac command executes fine and creates the .class file
but when i give the java command to interpret the file i get the following error
Exception in thread main: java.lang.NoClassDefFoundError : HelloWorld
i have given whatever classpath i needed to give, note though that when i installed jdk1.3, i had a src.jar file which i think is the file where the path should point to, this was initially not located in the lib folder
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
If your class is in a package, make sure you also include tha package name when trying to interpret. You can do a fimd for the class file created, then navigate to that directory and issue the command from there.


So much trouble in the world -- Bob Marley
Lucas Richardson
Ranch Hand

Joined: Jul 08, 2001
Posts: 32
The problem isn't with java.exe not running. If it couldn't find the file, it would say "Bad Command or file name" (win 9x).
Post your source code. That error indicates that it's having a problem with your main method (like maybe it isn't there?)
Laojar Chuger
Ranch Hand

Joined: Dec 20, 2000
Posts: 111
Most likely it was an error of wrong class path. Just type set classpath=.; and see what happens.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
src.jar has NOTHING to do with anything. That is just included with the stuff so that you can read the Sun code if you want.
The CLASSPATH should include the \bin where the Sun files are, the "." current directory (probably) for convenience, and the directory where YOUR class file reside.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
Try this -- at the command prompt give
java classname
where classname is the name of the class as you specified in your code keeping in mind that Java is case sensitive . If this makes your code work then what u need to do is save the file as "" & make sure that the class name in your code is "Helloworld" .
And if it is not this simple excuse my ignorance .
[This message has been edited by Ashish Hareet (edited July 14, 2001).]
[This message has been edited by Ashish Hareet (edited July 14, 2001).]
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
you have to set your classpath for the current directory where your java file is at.
I agree. Here's the link:
subject: cannot execute java command from command prompt
It's not a secret anymore!