apache.commons 中带有 SwallowedExceptionListener 的 NoClassDefFoundError

NoClassDefFoundError with SwallowedExceptionListener in apache.commons

我有这个运行时异常。我正在使用 IntelliJ IDEA。 我已经从 apache 的站点下载了 apache commons dbcp2

到目前为止一切顺利,但现在,我通过“文件”>“项目结构”添加该模块。

Module addition

如您所见,我对 MySQL 库执行了相同的步骤,一切正常;事实上,当我输入 apache common 包中出现的函数时,不会出现任何错误。例如BasicDataStructure

public static DataSource getDataSource(){
    BasicDataSource ds = new BasicDataSource();
    ds.setUrl(JDBC_URL);
    ds.setUsername(JDBC_USER);
    ds.setPassword(JDBC_PASS);

    ds.setInitialSize(3);
    return ds;
}

但在时间 运行 它:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/pool2/SwallowedExceptionListener
at datos.Conexion.getDataSource(Conexion.java:19)
at datos.Conexion.getConnection(Conexion.java:33)
at test.ManejoPersonas.main(ManejoPersonas.java:25)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.SwallowedExceptionListener
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 3 more

这是我的.iml

<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
 <component name="NewModuleRootManager" inherit-compiler-output="true">
  <exclude-output />
  <content url="file://$MODULE_DIR$">
   <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
  </content>
  <orderEntry type="inheritedJdk" />
  <orderEntry type="sourceFolder" forTests="false" />
  <orderEntry type="module-library" exported="">
   <library>
    <CLASSES>
      <root url="jar://$USER_HOME$/Documents/JAVA Libraries/mysql-connector-java-8.0.19/mysql-connector-java-8.0.19/mysql-connector-java-8.0.19.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />
  </library>
</orderEntry>
<orderEntry type="module-library" exported="">
  <library>
    <CLASSES>
      <root url="jar://$USER_HOME$/Documents/JAVA Libraries/commons-dbcp2-2.7.0-bin/commons-dbcp2-2.7.0/commons-dbcp2-2.7.0.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />
  </library>
 </orderEntry>
</component>
</module>

我不知道为什么,因为我在编码时没有任何问题。 非常感谢。

看起来您还需要 Apache Commons Pool 项目中缺少的依赖项。