Installing Third-party JARs to a Maven Project — 2

In the previous post, we discussed how to install a third-party JAR file to the locally .m2 repository.

In this post let us proceed with the remaining options.

Adding third-party JAR to the Project as a System-Scoped file

Include the .jar file directly to the maven project (without installing to the .m2 repository) as a dependency with “systemPath” parameter.

Please find the below example of adding the claim-manager jar file as a system-scoped file.

Installing third-party Jar as a System-Scope file

This approach and installing the third-party jar to the local .m2 location is only recommended to be used as a short term fix, as it is not scalable when sharing third-party jars across multiple developers. Each developer has to install the jar in the local system using either way.

Adding the third-party JAR as an IntelliJ Project Dependency

  • Open the Maven project in IntelliJ to which the jar needs to be added.
  • Navigate to the “Open Module Settings” options by right-clicking the project.
  • Navigate to the “Project Settings -> Libraries” section and add the dependency jar by + option to Java.
Import the third-party jar to the libraries

This is a quick hack for getting things working. But this doesn’t scale or help to share the jar with other people.

Hosting the third-party JAR in a repository management tool like Nexus Or Archiva.

When we move the project from one environment to the other (development, staging, pre-production, and production) we need to set up these third party jars again and again. This is a hindrance to the Continues Integration Continuous Delivery process (CI-CD process).

To overcome this challenge we have Repository Management tools, which we can install locally and maintain a shared cache of jar files across the organization.

Repository manager Or a binary repository manager is a, software tool designed to optimize the download and storage of binary files used and produced in software development.

It centralizes the management of all the binary artifacts generated and used by the organization to overcome the complexity arising from the diversity of binary artifact types, their position in the overall workflow and the dependencies between them.

There are several advantages to using a repository management system.
Main advantages are,

  • Faster Builds.
    Dependencies are cached locally in the centralized repository and thus eliminates the overhead of downloading from the public internet, thus reduces the build times.
  • Saving the bandwidth and controls the traffic.
    Saves the overall bandwidth of the Organisation and eliminates excessive traffic to the maven central repository.
  • Predictability and Stability.
    Since we are not relying on network connectivity. We can be stable and run builds even during network outages.
  • Ability to host third party artifacts.
    Instead of hosting the jar locally, we can host it in the nexus repository which will be shared across developers and also maintained in the local cache.

There are several repository management tools available. Archiva and Nexus are two popular ones. You can download and install Archiva from here and Nexus from here.

References :

[2] https://www.sonatype.com/product-nexus-repository

Let us continue to explore how we can publish the dependency to maven central repository in the next post.

Thank you for reading!!!

Senior Software Engineer @WSO2, B.Sc.(Hons).Computer Engineering