简体   繁体   English

第三方库的NoClassDefFoundError

[英]NoClassDefFoundError for third party libraries

I successfully build and run my application in IntelliJ using Gradle plugin My dependencies described as 我使用Gradle插件成功构建并在IntelliJ中运行我的应用程序。我的依赖项描述为

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 1)您需要在类路径中添加依赖的jar,或者

2) package your project by creating a jar with dependencies 2)通过创建具有依赖项的jar来打包项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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