Using Apache Commons Numbers in a Java JDK 14 and Netbeans 12.1

Using Apache Commons Numbers in a Java JDK 14 and Netbeans 12.1

I am developing some applications written in Java. For some functions I need to use the Apache Commons library.

Previously, I was using Netbeans 12.0 and all was OK.

Description of the new problem.

I have created a global library (Commons-numbers) including

commons-numbers-complex-1.0-beta1.jar

The targeted project (a Java Modular Project), in my case « pacte-basics », includes the path to this global library in the Modulepath (Project Properties/Libraries/Compile)

That yields to strange error messages :

error: duplicate module on application module path

module in commons.numbers.field

error: duplicate module on application module path

module in commons.numbers.angle

...


Solution

  1. Download the source version of the Apache Commons Numbers library.

  2. Create a Java Modular Project, in my case « Apache-Commons »

  3. Create a Module, in my case « commons.numbers ». The use of module paths is useful in case of numerous modules.

  4. Create the associated package org.apache.commons.numbers.complex, to be compatible with future Apache Commons libraries that will solve the problem.

  5. Import all needed sources, in my case Complex.java

  6. Modify the module-info.java class to correspond to,

    module commons.numbers {

    exports org.apache.commons.numbers.complex;

    }

  7. Clean and Build, the Project Apache-Commons

  8. In the targeted Modular Module, in my case « pacte-basics », add the project « Apache-Commons » in the Libraries properties, Modulepath, using Add Project.

  9. Each modules using « numbers » must include in its module-info.java, the line

    requires commons.numbers;

For the case of Commons IO, that need further source files to satisfy dependencies.