0

This is a very stupid question, but I am all out of ideas and cannot find helpful issues online.

I am trying to use the math3 package in my Java project. Easy right?

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

Doing the import like that obviously gives me (in Eclipse, Version: Oxygen.3a Release (4.7.3a)) a "The import org.apache.commons.math3 cannot be resolved". This is expected, so I go to my Maven file (pom.xml) and add in:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-math3</artifactId>
    <version>3.4.1</version>
</dependency>

Fine. Now, I do "mvn install", and I see:

Downloading from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-math3/3.0/commons-math3-3.0.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-math3/3.0/commons-math3-3.0.jar (1.3 MB at 4.8 MB/s)

Ok, good, the jar was downloaded to my .m2 directory. I can check that it's there:

~/.m2/repository/org/apache/commons/commons-math3/3.4.1

Cool. So now, I go back to Eclipse, and nothing changed, it still gives me a "The import org.apache.commons.math3 cannot be resolved".

So what dumb thing am I doing/missing?

I tried to go the Eclipse route, with right click on pom.xml ; Maven --> Add Dependency ; manually add the group id, artifact id, version, and click OK. This changed nothing.

In Eclipse, when I click on pom.xml, I do see the commons-math3 jar in the "Dependencies" tab, but it does not appear in the "Dependency Hierarchy" tab. In the "pom.xml" tab, no issue, the dependency is there. But it does not show in the "Effective POM" tab...

It's driving me crazy.

William Abma
  • 415
  • 3
  • 14
  • You may want to try this: https://stackoverflow.com/questions/2030064/how-to-run-eclipse-in-clean-mode-what-happens-if-we-do-so – Andrew Mar 17 '21 at 16:12
  • Interesting! Doing so is now showing me the commons-math3 dependency in the "Effective POM" as well as in the "resolved dependencies" of the "Dependency Hierarchy" tab. I still get the import error, and I still don't see it in the "Maven Dependency file explorer" in eclipse but that's a step forward. I'm going to let Eclipse load for a while (I still see the blue "thinking bar" at the bottom right, though not sure what it's doing) – William Abma Mar 17 '21 at 16:32

1 Answers1

0

Aaaaah.

I was indeed missing a step, which was, in Eclipse, to right click on the project --> Maven --> Update Project

This finalized the loading of the POM dependencies.

I'm not sure why it wasn't done by default on the few methods I tried to add the dependency, but I must say I do not control Eclipse whatsoever. Learn your IDE would be my advice to myself.

William Abma
  • 415
  • 3
  • 14