3

So I've been looking for a while, and found that I need to import the

org.apache.commons.math3.util.ArithmeticUtils

library in a Java program I'm writing. Now this is my first Java program, and I can't figure out how to use the library.

Am I missing something here? Do I need to attach an option when I'm using the command?

javac MyProgramNameGoesHere.java -something(?)

Or is there some special place where I need to install the the library package to?

Edit::

I am also doing this with gEdit and the bash terminal, not an IDE.

As stated above I am using Ubuntu, so if there is some repository that I can install it from that would be nice to know of, or if I have to manually download it, where do I put it?

Community
  • 1
  • 1
Tropical_Peach
  • 1,143
  • 3
  • 16
  • 29
  • 1
    I suggest you use IDE and a build system like maven. This will allow you to add dependencies once (and it will automatically download and configure it's use) As you get more and more complicated, this can be very useful. I have seen one project which use 357 JARs, and they didn't write them all on the command line ;) – Peter Lawrey Jun 04 '13 at 05:47
  • I'm sure I'll have to at some point, but I'm still learning and when I'm learning a language I prefer doing everything with gedit and bash, so that I can learn this kinda thing, but thanks ;) – Tropical_Peach Jun 04 '13 at 06:05
  • 1
    It depends on whether you want to learn to program in Java or want to learn how to use the tools (which you might never use again) BTW an IDE is a standard tool for most professional developers. I generally suggest people focus on the programming first. – Peter Lawrey Jun 04 '13 at 06:36
  • 3
    Right, but if you start out with just a bash and a text editor you usually learn more about how the language works and moves than how to avoid errors and whatnot. Not saying IDE's are bad or whatever, just that I like to work with the raw parts first so I know whats going on. – Tropical_Peach Jun 04 '13 at 09:48

2 Answers2

4

To install Apache Commons use:

sudo apt-get install libcommons-math-java

Set the classpath to whichever directory contains the library you are using. Something like:

javac -classpath .:/library/directory/path/ MyProgram.java

Run man javac for more information.

Segmented
  • 795
  • 6
  • 13
  • Thanks this helped, however I'm still getting errors telling me that the package doesn't exist. – Tropical_Peach Jun 04 '13 at 06:41
  • 2
    This is probably dumb but since we're using apt-get how do you know what the library/directory/path that it is installed to? – emschorsch Feb 27 '15 at 03:12
  • 1
    @emschorsch not dumb, but a new question perhaps? However it has already been asked here http://askubuntu.com/questions/129022/determine-destination-location-of-apt-get-install-package =) – Segmented Feb 27 '15 at 03:46
0

Download the jar file for ArithmeticUtils from here, and run:

javac -cp commons-math.jar:. MyProgramName.java

What you're saying here is: 'Include all of the classes in the common-math.jar in my compilation, and also any classes in the current directory'.

As a side note - why aren't you using an IDE? It will make your life a lot easier.

Amir Afghani
  • 37,814
  • 16
  • 84
  • 124
  • 2
    I don't like to use IDE's when I first learn a programming language for exactly that reason, I need to LEARN the language, not just learn how to avoid errors. I've never used an IDE in C or C++ and on average I'm better for it. It's just a personal preference I guess. – Tropical_Peach Jun 04 '13 at 06:00
  • ##Also as an aside this would have been more helpful if you had said where to install it to...## – Tropical_Peach Jun 04 '13 at 06:26