1

I've written a program to read in data from a text file and do some simple calculations, then print out those calculations. That part works great.

Afterward, I added in some code to do a t-test, using the TTest class (org.apache.commons.math3.stat.inference.TTest). So, I downloaded commons-math3-3.6.jar from the Apache Commons download page and put the JAR file in the same folder as the rest of my Java code for this program.

I use the following command in Windows to compile, which works fine:

javac -cp ./commons-math3-3.6.jar ./FootballTeam.java ./Main.java

But I can't figure out how to correctly run the program. I've tried this:

java Main

which executes everything up to the t-test perfectly, and then gives the expected error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/stat/inference/TTest at Main.main(Main.java:32) Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.stat.inference.TTest at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more

I've also tried this:

java -cp commons-math3-3.6.jar Main

which gives me this:

Error: Could not find or load main class Main

I cannot for the life of me figure out how to properly set the classpath here. Can someone provide me some assistance? Thank you!

1 Answer 1

1

The Main class cannot be found because the current directory (.) is not on your classpath.

To add it, on Windows:

java -cp ".;commons-math3-3.6.jar" Main

On *n?x:

java -cp ".:commons-math3-3.6.jar" Main
Sign up to request clarification or add additional context in comments.

1 Comment

Oh my freaking god. The instructions I was given was to do ".:" only, and so I never tried ".;" because I didn't know about it. Such a simple solution! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.