第三方库

时间:2016-05-31 21:48:47

标签: java intellij-idea gradle command-line noclassdeffounderror

我使用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"
    ...
}

当我从命令行运行我的应用程序时,收到错误消息:

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

如何解决此错误?

1 个答案:

答案 0 :(得分:0)

1)您需要在类路径中添加依赖的jar,或者

2)通过创建一个带依赖关系的jar来打包你的项目