2

I forked one project from github and when i want to run it gives error. I added org.json jar file to jdk\lib and also set the Path variable to it. I compiled code but it got no errors but when i run it i get exception as follows : (and I am running it using command prompt)

Error: A JNI error has occurred, please check your installation and
try 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

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
Pratik
  • 88
  • 1
  • 2
  • 11
  • 1
    You should add an [MCVE](https://stackoverflow.com/help/mcve) so that somebody can reproduce your problem and hopefully help you. – IKavanagh Aug 16 '15 at 11:18

1 Answers1

3

Add required jar to classpath like this:

  1. For *nix-like systems:

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

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

...or via manifest:

Manifest-Version: 1.0
Main-Class: MyApp
Class-Path: /lib/json.jar
ankhzet
  • 2,517
  • 1
  • 24
  • 31
  • 2
    @Pratik, not **PATH** but **CLASSPATH**. First is used by system for file-finding, secon - by JVM for **dependencies** finding, like yours org.json.jar – ankhzet Aug 16 '15 at 11:42
  • also, you can try to extract contents of org.json.jar by some unzip program and add them into yours main `.jar`, but that not always working (for ex., if jar's are signed) – ankhzet Aug 16 '15 at 11:45