A JNI error has occured when running my program as a JAR from IntelliJ

Viewed 187

My code compiles and runs without issue in IntelliJ. However when I try building the program as a JAR and running in cmd, I get the following error.

Error: A JNI error has occurred, please check your installation and
try again Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/log4j/Layout
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
        at java.lang.Class.getMethod0(Class.java:3018)
        at java.lang.Class.getMethod(Class.java:1784)
        at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:650)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Layout
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
        ... 7 more

I believe I am creating the JAR correctly. Here are the libs I am bundling in. enter image description here

I create the JAR by adding an empty JAR to the artifacts tab, then adding the META-INF, libs, and code manually. enter image description here As you can see, lib is contained inside which does hav log4j and apache commons.

Note this issue only pops up when the JARs are created from IntelliJ. If I create a JAR via eclipse the JAR works just fine, but that isn't viable.

0 Answers
Related