如何解决jdom库运行时异常?
我想使用 jdom-1.1.jar
库文件从 java 代码创建一个 kml 文件。它没有给我的程序提供编译时错误,但显示运行时错误:
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.
我该如何解决此类错误..
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..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您绝对必须告诉 Java 在哪里可以找到 jdom 库(以及您可能需要的其他库)。假设您的库位于某个文件夹
/dev/lib
中,那么正确的命令如下所示:此命令进一步假设文件
KmlSample.class
位于当前位置和类KmlSample
在默认命名空间中定义的位置(KmlSample.java
没有package
语句)并且KmlClass
有一个正确的main
方法(入口点)。编辑
这应该可以工作(或者至少应该产生不同的错误消息)
确保当前目录(在上面的示例中执行java的位置)包含该文件
KmlSample.class
(看看我答案的上半部分)。您提到了该位置的KmlSample.java
文件 - 您编译了源代码吗?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:This command further assumes that the file
KmlSample.class
is at the current location and that the classKmlSample
is defined in the default namespace (KmlSample.java
does not have apackage
statement) and theKmlClass
has a correctmain
method (entry point).Edit
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 aKmlSample.java
file at that location - have you compiled the source?您需要在类路径上添加 jdom-1.1.jar,以便显示您如何运行程序,应该像
you need to add jdom-1.1.jar on your classpath, so show how you are running your program, should be like