简体   繁体   中英

NoClassDefFoundError with Apache commons math

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!

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.

In my case, I'd forgot just to add part of Apache library is the name: commons-math3-3.6.1.jar

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM