aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Running compiled code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Running compiled code" Watch "Running compiled code" New topic
Author

Running compiled code

Amar Das
Greenhorn

Joined: Dec 18, 2000
Posts: 1
I was just testing the installation of java on my machine. I wrote the following program and saved it as Hello.java. Then I compiled it using javac Hello.java. It compiles fine. But when I try to run it using java Hello I got the following error messageException in thread "main" java.lang.NoClassDefFoundError: Hello
My code sample for Hello
-------------------------
public class Hello {
public static void main (String[] args){
System.out.println("Hello World!");
}
}
What is wrong. Thanks for help.
Axl Rose
Greenhorn

Joined: Dec 18, 2000
Posts: 16
Amar, you need to set your classpath so that it points to the directroy of your Hello.class file.
you can do this easily from the DOS
let us assume that your Hello.class file is in the following directory
C:\Amar\classes\Hello.class
then you set the path in the dos like this way
C:\>set classpath=%classpath%;c:\Amar\classes
and then you can run the class using <java Hello>
if your class is inside a package, you follow the same step
and point to the directory of your package.
Hope this can help
naveen sahu
Ranch Hand

Joined: Nov 15, 2000
Posts: 48
Originally posted by Amar Das:
I was just testing the installation of java on my machine. I wrote the following program and saved it as Hello.java. Then I compiled it using javac Hello.java. It compiles fine. But when I try to run it using java Hello I got the following error messageException in thread "main" java.lang.NoClassDefFoundError: Hello
My code sample for Hello

after compilling see the directory listing of your current directory in which your class hello existing.
read the name of that class carefully with propercase (upper/lower) and then execute command
java "your class name wihout extension"
every thing will be fine.
this is the mistake due to uppercase lowercase mistake & nothing else.
check name of the .class file created after compillation and then execute above command
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running compiled code