线程“main”中的异常java.lang.NoClassDefFoundError:org / joda / time / ReadableInstant [英] Exception in thread "main" java.lang.NoClassDefFoundError: org/joda/time/ReadableInstant

查看:1953
本文介绍了线程“main”中的异常java.lang.NoClassDefFoundError:org / joda / time / ReadableInstant的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ant脚本构建了一个可执行jar,我使用的唯一外部jar是joda-time 2.0。 ant构建脚本似乎工作,因为我没有收到任何编译错误,如果我要从lib目录中删除jode-time 2.0.jar,那么构建确实会按预期失败。无论如何,在构建jar之后,当我尝试运行时出现此错误:

I built an executable jar using an ant script, the only external jar I used was joda-time 2.0. The ant build script "seemed" to work as I did not recieve any compile errors, and if I were to remove the jode-time 2.0.jar from the lib directory the build would indeed fail as expected. At any rate, after building the jar I get this error when I try to run with:

java -jar myapp.jar

java -jar myapp.jar

线程main中的异常java.lang.NoClassDefFoundError:org / joda / time / ReadableInstant

Exception in thread "main" java.lang.NoClassDefFoundError: org/joda/time/ReadableInstant

对此有何想法?我只是不确定在哪里看,在Eclipse中一切正常。感谢任何想法

Any thoughts on this? I'm just not sure where to look, everything works just fine within Eclipse. thanks for any ideas

推荐答案

据推测,你的jar不包含清单头告诉Java将joda-time jar添加到类路径中。这是使用 java -jar 时获得其他类路径条目的唯一方法。您可以使用Ant 清单任务直接执行此操作,或者可能有多个其他方法,包括从现有的类路径构建它。

Presumably, your jar doesn't contain a manifest header telling Java to add the joda-time jar to the classpath. That's the only way to have other classpath entries when using java -jar. You could do this directly with the Ant manifest task, or there are probably multiple other ways to do it, including building it from your existing classpath.

或者,尝试

java -cp myapp.jar:joda-time-2.0.jar com.foo.YourMainClass

这篇关于线程“main”中的异常java.lang.NoClassDefFoundError:org / joda / time / ReadableInstant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆