【问题标题】:Java JSON Jar NoClassDefFound Caused by ClassNotFoundExceptionJava JSON Jar NoClassDefFound 由 ClassNotFoundException 引起
【发布时间】:2014-10-25 19:31:49
【问题描述】:

我有一个简单的 java 文件,在 PHP 脚本调用的服务器上打包为 Jar。我的 java 程序中包含“json-simple-1.1.1”库。但是,当我运行时,它给了我以下错误。我已将 json-simple jar 添加到我的项目中并导入正确的类。从我读过的内容来看,它似乎没有将 json-simple 库添加到我的清单文件中。有想法该怎么解决这个吗。如果有帮助,我正在使用 eclipse。

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2570)
    at java.lang.Class.getMethod0(Class.java:2813)
    at java.lang.Class.getMethod(Class.java:1663)
    at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.ParseException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

【问题讨论】:

  • 可能您需要自己将库添加到清单中,例如 here

标签: java json eclipse error-handling libraries


【解决方案1】:

您的库可能没有被类加载器加载,所以,如果它不在 WEB-INF/lib 中,请右键单击它并Add to build Path

【讨论】:

  • 我没有 web-inf/lib 文件夹。我只有一个“引用库”文件夹,其中包含 json-simple.jar 库。当我右键单击 - 构建路径时 - 它已经说它已添加到构建路径中。
  • 嗯好的,所以它可能是清单,看看这个链接fraaargh.wordpress.com/2008/07/13/…@Hanno 提供
  • 我应该用什么代替“myCustomLibPath2”?我当前的清单看起来像这样 Manifest-Version: 1.0 Main-Class: test.HelloWorld Class-Path: myCustomLibPath2/json-simple-1.1.1.jar
  • 这是您的 jar 所在的路径,从项目的根目录开始。也许这个也可以帮助你:docs.oracle.com/javase/tutorial/deployment/jar/downman.html
  • 这看起来非常复杂。 Eclipse 不能只用 java 文件和包含的库创建一个 jar 文件,而不必手动将每个 3rd 方库添加到清单中?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多