Sizons Sizons - 25 days ago 9
Java Question

how do I import org.apache.commons.lang3.ArrayUtils; into Eclipse

How do I import:

org.apache.commons.lang3.ArrayUtils


library into a new project within the Eclipse Development Environment. Is there a package manager I can use or do I need to download a dll or binary and then reference it somehow within my codebase?

I have seen similar questions but none really goes step by step to explain how one can import this library into Eclipse.

Answer

First of all, you should have a Project. Right Click Eclipse Project from the Project or Package explorer

Properties -> Java Build Path -> Libraries

From here select:

  1. 'Add jar' if the jar is within your project
  2. 'Add external jar' if it is on your file system
  3. 'Add variable', if you have configured a variable in eclipse that points to the directory containing the jar files or the jar file itself (See how to configure variables below)
  4. 'Add library' if you have configured the jars into a library (see below for library configuration)
  5. 'Add class folder' if you just have a bunch of classes in a directory that should be used for classes/resources which is part of one of your projects
  6. 'Add class folder' if you just have a bunch of classes in a directory that should be used for classes/resources which is in your file system

Configuring variables:
Eclipse select menu: Window -> Preferences -> Java -> Build Path -> Classpath Variables

Select New and give a Name and select a file or folder

Configuring libraries:

Eclipse select menu: Window -> Preferences -> Java -> Build Path -> User Libraries -> New

Provide a name and in that you can add jars from within a project or from the file system just like how it is mentioned above.


NOTE: In some cases, it might be convenient to allow build tools like gradle or maven or ant with ivy to manage your dependencies for a project (when i mean dependencies i mean libraries) as some project have about a few hundred jars as dependencies, and manually managing them might be painful. These build tools have the functionality of downloading the jars and its sources for you automatically by just adding an entry in a file and even caching it for later use.

See https://gradle.org/ for gradle
See https://maven.apache.org/ for maven