简体   繁体   中英

NoClassDefFoundError for third party libraries

I successfully build and run my application in IntelliJ using Gradle plugin My dependencies described as

dependencies{
    compile fileTree(dir: 'libs', include: '*.jar')
    ...
    compile "org.apache.httpcomponents:httpmime:4.5.2"
    compile "org.apache.httpcomponents:httpclient:4.5.2"
    compile "org.apache.commons:commons-configuration2:2.0"
    ...
}

When I run my app from command line I get an error message:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError:     org/apache/commons/configuration2/ex/ConfigurationException
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:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.configuration2.ex.ConfigurationException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

How can I solve this error?

1) You need to add the jars you are dependent on on your classpath, or

2) package your project by creating a jar with dependencies

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM