I have downloaded the apache match package to my machine and compiled the code below without error, but when I run the class I got the error "ClassNotFoundException: org.apache.commons.math3.distribution.NormalDistribution"
import org.apache.commons.math3.distribution.NormalDistribution;
public class CumulativeProbability {
private static NormalDistribution nd;
public static void main(String[] args) {
nd = new NormalDistribution(100.30 , 232.45);
System.out.println(nd.cumulativeProbability(3000));
nd = new NormalDistribution(50.3, 10.1);
System.out.println(nd.inverseCumulativeProbability(0.7));
}
}
The error message:
C:\Distnormal>java CumulativeProbability Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/distribution/NormalDistribution at CumulativeProbability.main(CumulativeProbability.java:9) Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.distribution.NormalDistribution
Trying with the command: C:\Distnormal>java -cp "C:\Distnormal\commons-math3-3.6.1.jar" CumulativeProbability Error: Could not find or load main class CumulativeProbability
below how I'm compiling: C:\Distnormal>javac -cp "C:\Distnormal\commons-math3-3.6.1.jar" CumulativeProbability.java
I double-checked everything but could not find where the error is.
I already double-checked the source code, the jar file but not able to fix the error.
CodePudding user response:
I tried your main program and I can compile it and run it successfully with commons-math3-3.6.1.jar. I'm working on Ubuntu Linux.
Compile:
$ javac -d . -cp commons-math3-3.6.1/commons-math3-3.6.1.jar CumulativeProbability.java
The -d .
means for javac to write .class files into .
(i.e., current working directory).
Run:
$ java -cp commons-math3-3.6.1/commons-math3-3.6.1.jar:. CumulativeProbability
1.0
55.5964451783512
Note that I put .
on the classpath, otherwise java
doesn't find CumulativeProbability.
I think it must be a problem with the -cp
option for you. Try this: write the path as either "C:\Distnormal\commons-math3-3.6.1.jar" (i.e. with two backslash characters) or "C:/Distnormal/commons-math3-3.6.1.jar" (i.e. with one forward slash character).