如何解决jdom库运行时异常?

发布于 2024-10-19 13:52:00 字数 785 浏览 6 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

星星的軌跡 2024-10-26 13:52:00

您绝对必须告诉 Java 在哪里可以找到 jdom 库(以及您可能需要的其他库)。假设您的库位于某个文件夹 /dev/lib 中,那么正确的命令如下所示:

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

此命令进一步假设文件 KmlSample.class 位于当前位置KmlSample 在默认命名空间中定义的位置(KmlSample.java 没有 package 语句)并且KmlClass有一个正确的main方法(入口点)。


编辑

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

这应该可以工作(或者至少应该产生不同的错误消息)


确保当前目录(在上面的示例中执行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:

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

gt; cd C:\programfiles\tomcat\tomcat-5.5.9\webapps\jsp-examples
gt; 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?

王权女流氓 2024-10-26 13:52:00

您需要在类路径上添加 jdom-1.1.jar,以便显示您如何运行程序,应该像

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文