gpt4 book ai didi

java - 如何添加 jar 文件并使用命令提示符进行编译? (错误 : A JNI error has occured, 请检查您的安装)

转载 作者:行者123 更新时间:2023-11-30 08:09:53 25 4
gpt4 key购买 nike

我从 github 上 fork 了一个项目,当我想运行它时出错。我将 org.json jar 文件添加到 jdk\lib 并为其设置了 Path 变量。我编译了代码,但没有错误,但是当我运行它时,出现如下异常:(我正在使用命令提示符运行它)

Error: A JNI error has occurred, please check your installation andtry again Exception in thread "main" java.lang.NoClassDefFoundError:org/json/JSONExceptio n        at java.lang.Class.getDeclaredMethods0(Native Method)        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)        at java.lang.Class.privateGetMethodRecursive(Unknown Source)        at java.lang.Class.getMethod0(Unknown Source)        at java.lang.Class.getMethod(Unknown Source)        at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source) Caused by: java.lang.ClassNotFoundException:org.json.JSONException        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)

... 7 more

最佳答案

像这样将所需的 jar 添加到类路径中:

  1. 对于 *nix 类系统:

    export CLASSPATH=<path-to-app>/myapp.jar:<path-to-app>/lib/json.jar:.
    java MyApp
  2. 对于 Windows:

    set CLASSPATH=<path-to-app>/myapp.jar;<path-to-app>/lib/json.jar;.
    java MyApp

...或通过 list :

Manifest-Version: 1.0
Main-Class: MyApp
Class-Path: /lib/json.jar

关于java - 如何添加 jar 文件并使用命令提示符进行编译? (错误 : A JNI error has occured, 请检查您的安装),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32034444/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com