NoClassDefFoundError with Apache commons math

混江龙づ霸主 提交于 2020-12-14 07:17:30

问题


I want to use the PoissonDistribution from Apache Commons but always get the error a NoClassDefFoundError.

The code:

import org.apache.commons.math3.distribution.PoissonDistribution;

public class Test {

    public static void main(String[] args) {
        PoissonDistribution p = new PoissonDistribution(5.0);

    }

}

The error message:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/distribution/PoissonDistribution
    at Test.main(Test.java:6)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.distribution.PoissonDistribution
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 1 more

What I've done so far: The commons-math3-3.6.1.jar file is located in a folder inside my project folder and via Project->Properties->Java Build Path->Libraries I added the JAR file and then in the "Order and Export" tab next to it I selected the jar file.

Thanks for your help!


回答1:


Make sure your PoissonDistribution class available in Java Classpath. And i can guess your jar will not in add jar properly.

Add following step to add jar :

  • Eclipse by right-clicking on the Project
  • Build Path
  • Add External JARs.
  • And give the Jar.
  • Ok



回答2:


Ok so by coincidence I've found the solution:

My problem was that I added the JAR to the Modulepath and not the Classpath in the project properties.



来源:https://stackoverflow.com/questions/58673427/noclassdeffounderror-with-apache-commons-math

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!