0

I just installed the Apache Commons math library with apt (libcommons-math3-java) on my debian machine and apparently it gets installed to the /usr/share/java directory:

$ ls /usr/share/java | grep math
commons-math3-3.3.jar
commons-math3.jar

But importing the package in Java doesn't work:

import org.apache.commons.math3.*;

class TestClass {
public static void main(String[] args) {
    System.out.println("Hello? World?");
}
}

Trying to compile produces the following result:

$ javac TestClass.java
TestClass.java:1: error: package org.apache.commons.math3 does not exist
import org.apache.commons.math3.*;
^
1 error

How do I use the library? Please help.

nradk
  • 680
  • 9
  • 19
  • Add it to the classpath javac -cp /usr/share/Java/commons-math3-3.3.jar TestClass.java – Jens Jul 28 '16 at 15:15
  • 2
    It is never a good idea to use java libraries packaged as apts. They are arbitrarily messed up. Learn to use Maven or Gradle or Ant/Ivy which will download what you need from clean versions in Maven central. – bmargulies Jul 28 '16 at 15:15
  • I started using Maven and its making things a lot easier. Thanks. – nradk Aug 01 '16 at 16:45

1 Answers1

0

To add the functionality provided by this library to one of your projects, simply do the following:

1) Start Eclipse, and locate the project folder to which this library should be added.

2) Right-click this class folder, and select "Properties"

3) Select "Java Build Path" on the left, and then the "Libraries" tab. Now, click the "Add External JARS..." button

4) Locate and select the "libcommons-math3-java.jar" file you just downloaded, and then click "Open"

5) Finally, click "OK" to close the dialog box. You will know that everything went ok if, when you open your project folder, you see an item called "Referenced Libraries", and upon expanding this item, you see the package "libcommons-math3-java.jar" listed.

Kevin
  • 9
  • 2