How to Add External JAR Files to a Maven Project?

Ways to add JAR file to a Maven project

Having difficulty adding third-party external JAR files to your Maven project? We’ve got the solution for you!

External JAR files are generally obtained from their own vendors — which makes integrating them into a Maven repository a nightmare. Technically speaking 🤓, you could leave the entire process in the hands of a professional, but what’s the fun in that?

In order to have a go at it, you’d need to hold a valid ownership license of the external JAR file from their specific vendors. 

All of this might sound a bit too “intense” in nature to a newbie 🤯, but luckily, we have automated plugins to take care of all that jitter-jatter!

JAR files are generally included to increase the functionality of your Maven project. However, writing dependency codes or trying to edit the POM file won’t work here since the file itself does not exist in the Maven project’s database.

Having said that, you’d have to perform different steps depending on the JAR file you have at hand. On a general scale, we limit these files to one of the following categories:

  1. Publicly Available Artifacts
  2. Downloaded Artifacts

With that out of the way, this article will showcase the methods needed to add an external JAR file to a Maven project. So, on that note, let’s jump right in 😏!



Using The MVN Command

The MVN command is currently the easiest method of installing external JAR files to your Maven repo. Just perform the following operations, and you’re mostly good to go!


1. Initiating the Command

The build command can be initiated through any StreamBase Command Prompts or StreamBase-configured terminal windows.

You will be using the following common in order to install any JAR file:

maven install:install-file


This command comes included with StreamBase version 10.3.0 and later. Therefore, you don’t need to do much. For the OG users of the platform 😎, running the earlier versions, the following steps might be necessary:

  1. For starters, set the JAVA_Home environment variable point to your JDK installation path. If you don’t have JDK installed, then consider downloading it from the official link.
  2. Next, extract the archives in the directory of your choice. Just be sure to save the path of that directory for later use. The extraction process can be done by entering the following commands — depending on your operating system:

tar xzvf apache-maven-version_no-bin.tar.gz


Replace the version_no with the actual version of the installed package before running the command. 

Once done, you’re pretty much good to go for this part. 



2. Determining JAR Parameters

The mvn command requires parameters to function. These can range from groupId, to version. You can take a deeper look at them through the following table:


Parameter Description
File Refers to the File Type and passes the file that’s needed to be installed in the local repository
artifactId Refers to the String Type and passes the ArtifactId of the Artifact that you want to install. It’s generally retrieved or extracted from the POM file. 
classifiers Takes in a String Type containing the artifact’s classifier type needed to be installed. 
generatePom Takes a Boolean value to generate a minimal POM for the artifact. Generally used when there’s no POM file in the repository. 
groupId Takes a String with the GroupId of the artifact that needs to be installed—usually retrieved from the POM file.
javadoc Takes a File Type as a parameter, and acts as bundled API docs for the artifact.
localRepositoryPath Takes the path for the Local Repository Directory. Maven will automatically use the path configured in the settings by default.
packaging Takes a String as the parameter type that contains the packaging type of the artifact that needs to be installed. By default, this value is generally taken from the POM file. 
pomFile Sends the location of an existing POM file that needs to be installed along the main artifact.
sources Takes a File Type containing a bundled form of the sources for the artifact
version This String parameter specifies the version of the artifact that needs to be installed. It’s retrieved from the POM file by default. 


Aside from these, you also need to follow some SOPs in order to ensure your project honors every component that’s outsourced:

  1. Always honor the vendor: Don’t deliberately hide the trade names on the package, and don’t self-invent random numbers. 😯
  2. Certain Artifacts come with parameters: If your external JAR file is sourced from sites like Maven Central, then you don’t have to go so roundabout since they come preloaded with parameters. 
  3. Fill in as many values as possible: Don’t leave parameters empty; always load your project with the correct information — whether it be determined or unknown. In the latter case, fill it with reasonable values. 



3. Rebuilding the Repository

Now that you’ve successfully installed the external JAR file, it’s time for some reconfigurations so your project can show it properly. 

You might not have to do this step depending on the scenario or the file’s use case 🤔. But if your file is not showing up in the project, consider implementing the following:

  1. In your specific studio, open the Repositories View, and invoke Window to head to Show View
  2. From there, select the Other button and type maven in the search tab. 
  3. Now, open Local Repositories, and select Rebuild Index in the context menu of the Local Repository submenu. 
  4. Lastly, select Rebuild Index and press Ok on the dialogue box. 

You will be able to use the project as needed once the repositories have been rebuilt. This process is generally instantaneous but can take a few minutes depending on the number of files and the processing speed. 




In essence, you can simply use the mvn plugin to install the external files. However, the true trick lies in how you configure your arguments 😬. There are a bunch of SOPs that you’d be better off following since they help in creating market-compatible software. 

Luckily, the complex part of the solution is already automated by the plugin so you don’t need to rack your brains over unnecessary stuff. 

Be sure to watch for status messages to confirm the completion of the rebuild process. The studio isn’t the most error-free software, so it sometimes does not work on the first invocation. 

In case you’re having difficulties with the parameters, we recommend you use the default values to create a dummy prototype first. 🧐

Lastly, let us know in the comments:

  1. Were you able to add your external JAR files to your Maven Project?
  2. Have you found a simpler plugin that can do all of this and more with lesser effort?
  3. What kind of project are you intending to create using Maven?
  4. Are there any other points or useful information you believe we should’ve mentioned?

Feel free to share this article amongst your friends and peers so they don’t have to rack their brains while trying out Maven. 



Leave a Reply

Your email address will not be published. Required fields are marked *