Pure Programmer
Blue Matrix


Cluster Map

Dependency Management

L1

This page is under construction. Please come back later.

It is often easier to write programs when you don't have to write all the code from scratch. There are a large number of code libraries available, both open source (free) and commercial (paid). Using code libraries written by the community or commercial developers give you a leg up in your coding efforts by making a large library of useful functions and classes available to your program. All we need to do is manage these dependencies and include them in our programs.

Java doesn't come with a package manager. Typically you can download pre-compiled Java libraries as .jar files from the website for that library. You then put these library files in your project folder and put them in the classpath so that your program can find them. For example assume that you have downloaded the library in [[Pure Programmer Java Utils Jar]] and placed the "Utils.jar" file in the same folder as your Java source file. Then type:

$ javac -cp Utils.jar Hello.java $ java -ea -cp .:Utils.jar Hello Hello

If you start to have more than just one or two library files that you routinely use, you might want to look into automatic dependency management using a build tool like [[Apache Maven]] or [[Gradle]].

To use the library in your source file simply add the following import statement at the top of your source file:

import org.pureprogrammer.Utils;
Importing Libraries in Java

You can also download the [[Pure Programmer Java Utils Class]] source if you want to build the jar file yourself.

References