Pratik Pratik - 1 year ago 310
Java Question

How to add jar files and compile using command prompt? (Error: A JNI error has occured,Please Check your Installation)

I forked one project from github and when i want to run it gives error. I added

jar file to
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:
at 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

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download