wood burning stoves 2.0*
The moose likes Java in General and the fly likes NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "NoClassDefFoundError " Watch "NoClassDefFoundError " New topic


John King

Joined: Dec 19, 2002
Posts: 5
I am testing one java class. Here is source code:
import java.io.*;
public class FileDemo {
public static void main (String [] args) throws IOException {
// Create instances of File objects for directory
// and file entries
File dir = new File(File.separator + "Wrox" + File.separator
+ "docs");
File f1 = new File(dir, "test1.txt");
File f2 = new File(dir, "test2.doc");
File f3 = new File(dir, "test3.txt");
//FileDemo f = new FileDemo();
// Create directory and files
System.out.println("Directory \\Wrox\\docs created");
System.out.println("Files \"test1.txt\" and \"test2.doc\" created");
// Get file attributes
System.out.println("\nAttributes of \"test1.txt\" \n" +
"\n\"test1.txt\" exists: " + f1.exists() +
"\n\"test1.txt\" is a file: " + f1.isFile() +
"\n\"test1.txt\" is a directory: " + f1.isDirectory() +
"\nCan read from \"test1.txt\": " + f1.canRead() +
"\nCan write to \"test1.txt\": " + f1.canWrite() +
"\nThe absolute path of \"test1.txt\": " + f1.getAbsolutePath());
// Rename test2.doc to test3.txt
System.out.println("\nThe name of the file object f2 is "
+ f2.getName());
System.out.println("Renaming :\"test2.doc\" to \"test3.txt\"");
System.out.println("The name of the file object f3 is "+f3.getName());
// Delete all files and directory
System.out.println("\nDeleting files and directory ");
System.out.println("The file \"test1.txt\" is deleted: "
+ f1.delete());
System.out.println("The file \"test3.txt\" is deleted: "
+ f3.delete());
System.out.println("The directory docs is deleted: "
+ dir.delete());
//FileDemo f = new FileDemo();
Here is what I did:
C:\>cd C:\jakarta-tomcat-4.1.12-src\webapps\ROOT\begjsp-ch14\src
C:\jakarta-tomcat-4.1.12-src\webapps\ROOT\begjsp-ch14\src>javac FileDemo.java
C:\jakarta-tomcat-4.1.12-src\webapps\ROOT\begjsp-ch14\src>java FileDemo
Exception in thread "main" java.lang.NoClassDefFoundError: FileDemo
No error message in compiling. But when I run it, I had NoClassDefFoundError. Any idea why I got this exception? I suspect the path problem. Thanks in advance
Greg Charles

Joined: Oct 01, 2001
Posts: 2851

Whoa deja vu! OK, so it's not in a package. You might try:
before you run it. However, I just compiled and ran it without any CLASSPATH variable being set. Can you run any Java programs on your system? Maybe something is fundamentally wrong with your set up.
John King

Joined: Dec 19, 2002
Posts: 5
I run a lot of JSP and Javabean in my machine without any problem. I am using Forte as well as command line to compile it.
John King

Joined: Dec 19, 2002
Posts: 5
I messed CLASSPATH when I installed Tomcat. It was:
It should be:
Now it works. Thanks for your help.
I agree. Here's the link: http://aspose.com/file-tools
subject: NoClassDefFoundError