英文:
NoClassDefFoundError with SwallowedExceptionListener in apache.commons
问题
我遇到了这个运行时异常。我正在使用IntelliJ IDEA。我从Apache的网站上下载了apache commons dbcp2
。
到目前为止,一切都很好,但现在,我通过文件 > 项目结构来添加该模块。
你可以看到我为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>
我不知道为什么会出现这个问题,因为在编码时没有任何问题。非常感谢。
英文:
I have this Runtime Exception. I'm using IntelliJ IDEA.
I've downloaded apache commons dbcp2
from apache's site.
So far so good, but now, I add that module by File > Project Structure.
As you can see I've done that same steps for MySQL Library, and its fine, all works; In fact, when I'm typing functions that appear in that apache common
package doesnt appears any error. For example 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;
}
But at time to run it:
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
This is my .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>
And I dont know why, because while I'm coding there arent any problem.
Thanks a lot.
答案1
得分: 0
看起来您的项目还需要Apache Commons Pool的依赖,但是目前缺失了这部分。
英文:
It looks like you also need Apache Commons Pool dependency in the project which is missing.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论