NoClassDefFoundError with SwallowedExceptionListener in apache.commons

huangapple go评论91阅读模式
英文:

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.

Module addition

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 &quot;main&quot; 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

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;module type=&quot;JAVA_MODULE&quot; version=&quot;4&quot;&gt;
 &lt;component name=&quot;NewModuleRootManager&quot; inherit-compiler-output=&quot;true&quot;&gt;
  &lt;exclude-output /&gt;
  &lt;content url=&quot;file://$MODULE_DIR$&quot;&gt;
   &lt;sourceFolder url=&quot;file://$MODULE_DIR$/src&quot; isTestSource=&quot;false&quot; /&gt;
  &lt;/content&gt;
  &lt;orderEntry type=&quot;inheritedJdk&quot; /&gt;
  &lt;orderEntry type=&quot;sourceFolder&quot; forTests=&quot;false&quot; /&gt;
  &lt;orderEntry type=&quot;module-library&quot; exported=&quot;&quot;&gt;
   &lt;library&gt;
    &lt;CLASSES&gt;
      &lt;root url=&quot;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!/&quot; /&gt;
    &lt;/CLASSES&gt;
    &lt;JAVADOC /&gt;
    &lt;SOURCES /&gt;
  &lt;/library&gt;
&lt;/orderEntry&gt;
&lt;orderEntry type=&quot;module-library&quot; exported=&quot;&quot;&gt;
  &lt;library&gt;
    &lt;CLASSES&gt;
      &lt;root url=&quot;jar://$USER_HOME$/Documents/JAVA Libraries/commons-dbcp2-2.7.0-bin/commons-dbcp2-2.7.0/commons-dbcp2-2.7.0.jar!/&quot; /&gt;
    &lt;/CLASSES&gt;
    &lt;JAVADOC /&gt;
    &lt;SOURCES /&gt;
  &lt;/library&gt;
 &lt;/orderEntry&gt;
&lt;/component&gt;
&lt;/module&gt;

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.

huangapple
  • 本文由 发表于 2020年4月8日 01:39:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/61086065.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定