How to solve runtime exception of jdom library?

9.2k Views Asked by At

I want to make a kml file from a java code using jdom-1.1.jar library file. It gives no compile time error to my program but showing a run time error:

C:\ProgramFiles\Tomcat\tomcat-5.5.9\webapps\jsp-examples>java KmlSample
Exception in thread "main" java.lang.NoClassDefFoundError: org/jdom/Content
Caused by: java.lang.ClassNotFoundException: org.jdom.Content
        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.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: KmlSample.  Program will exit.

how can i resolve such error..

2

There are 2 best solutions below

2
Andreas Dolk On BEST ANSWER

You definitily have to tell Java where to find the jdom library (and other libraries you may need). Assuming you have the library in some folder /dev/lib, then the correct command would be like this:

java -cp .;/dev/lib/jdom-1.1.jar KmlSample

This command further assumes that the file KmlSample.class is at the current location and that the class KmlSample is defined in the default namespace (KmlSample.java does not have a package statement) and the KmlClass has a correct main method (entry point).


Edit

$> cd C:\programfiles\tomcat\tomcat-5.5.9\webapps\jsp-examples
$> java -cp .;../../common/lib/jdom-1.1.jar KmlSample

This should work (or at least it should produce a different error message)


Make sure, the current directory (from where you execute java in the above example) contains the file KmlSample.class (have a look at the upper section of my answer). You mentioned a KmlSample.java file at that location - have you compiled the source?

4
MeBigFatGuy On

you need to add jdom-1.1.jar on your classpath, so show how you are running your program, should be like

java -classpath /path/to/jdom-1.1.jar;. YourMainClassFile