First Java Program Not Working

Hi All, I have installed JDK 6. I then created a new folder called C:\Test into which I saved
Aspose.Words.jdk16.jar ---- Test.doc ---- and Test.java shown below.
__________________________________Test.java

import com.aspose.words.Document;

public class Test
{
    public static void main(String args[])
    {
        try
        {
            Document doc = new Document("C:\\Test\\Test.doc");
            doc.save("C:\\Test\\TestOut.doc");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

I then compile Test.java using
C:\Test> javac -classpath Aspose.Words.jdk16.jar Test.java
It seems to compile ok but when I run the file using
C:\Test> java Test
I get the error message
---------------------------------------Error

Exception in thread "mail" java.lang.NoClassDefFoundError: com/aspose/words/Documentation
at Test.main(Test.java:11)
Caused by: java.lang.ClassNotFoundException: com.aspose.words.Document
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launger$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
...1 more

--------------------------------End Error
I should point out that when I run the simpler script below then everything works fine. Can someone tell me what I’m doing wrong here. Thanks


import com.aspose.words.Document;
public class Test
{
    public static void main(String args[])
    {
        try
        {
            System.out.println("abc");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

mister_mister:
Exception in thread “mail” java.lang.NoClassDefFoundError: com/aspose/words/Documentation

I’m not an Aspose employee but …
That seems like a strange error. There is no ‘mail’ thread nor (i’m guessing) is there a com/aspose/words/Documentation class.
Try running your program with the classpath set ie. java -classpath Aspose.Words.jdk16.jar Test

Sorry, that’s a typo. It should read
Exception in thread “main”
not
Exception in thread “mail”
Thanks for pointing this out
I tried running with the classpath set but unfortunately that gave the same error :frowning:
Thanks for you input though.

Hi
Thanks for your inquiry. I think that you should also specify path to your class. Try using the following:
java -classpath C:\Test;C:\Test\Aspose.Words.jdk16.jar Test
Hope this helps.
Best regards.

Great, thanks a lot. That solved the problem. :slight_smile: