Summary: I wanted to use the prime number functions in the Apache Common Math project to solve a prime number problem. The Apache NetBeans IDE 12.2 complains “cannot find symbol” isPrime() and the programs fails to compile.
What’s going on?
Detailed info:
Using Apache NetBeans IDE 12.2 running on Windows 10, I created a Maven Java app project. Then I followed the instructions posted by Ojonugwa Jude Ochalifuon on Mar 24 '18 Adding external JAR to Maven project in NetBeans
Specifically,
- I copied the Maven dependency XML from the Apache Math 3.6.1
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-math3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
and pasted it into my project’s pom.xml
Next, in the NetBeans 12.2 IDE, I performed a Clean and Build Project. The process downloaded all of the Apache Commons 3.6.1 files and compiled the project successfully. In the Projects tab, under the Dependencies folder, I saw the commons.math3-3.6.1.jar. I navigated down to the Primes.class.
Next, I added the following import command to my .java file:
import org.apache.commons.math3.primes.Primes;
The NetBean 12.2 IDE displayed a yellow squiggle under the import reporting “unused Import.”
- Then I added the following code snippet:
if (isPrime(candidate)) { … }
The NetBean 12.2 IDE displayed a red squiggle under the isPrime() method (which is defined in the Apache Math 3.6.1 package).
When I press Shift+F6 to run the file, I get the following compile-time error:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project ProjectEuler: Compilation failure robcor/projecteuler/Problem0027.java:[20,16] error: cannot find symbol
What’s going on?
Thanks in advance for your help. Much appreciated.