简体   繁体   English

NoClassDefFoundError 与 Apache 公共数学

[英]NoClassDefFoundError with Apache commons math

I want to use the PoissonDistribution from Apache Commons but always get the error a NoClassDefFoundError .我想使用来自 Apache Commons 的 PoissonDistribution,但总是收到错误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.到目前为止我所做的: commons-math3-3.6.1.jar 文件位于我的项目文件夹内的一个文件夹中,通过Project->Properties->Java Build Path->Libraries我添加了 JAR 文件,然后在“旁边的“订购和导出”选项卡我选择了 jar 文件。

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.我的问题是我将 JAR 添加到 Modulepath 而不是项目属性中的 Classpath。

In my case, I'd forgot just to add part of Apache library is the name: commons-math3-3.6.1.jar就我而言,我忘记了添加 Apache 库的一部分是名称:commons-math3-3.6.1.jar

Make sure your PoissonDistribution class available in Java Classpath.确保您的 PoissonDistribution class 在 Java 类路径中可用。 And i can guess your jar will not in add jar properly.我猜你的 jar 不会正确添加 jar。

Add following step to add jar:添加以下步骤以添加 jar:

  • Eclipse by right-clicking on the Project Eclipse 通过右键单击项目
  • Build Path构建路径
  • Add External JARs.添加外部 JARs。
  • And give the Jar.并给出Jar。
  • Ok好的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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