开发者

How to solve runtime exception of jdom library?

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 Km开发者_运维知识库lSample
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..


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?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜