A Maven based Java project I'm working on depends on a JAR file not hosted on Maven Central, or other public repo. Using GitHub, I created a personal Maven repository that allows the dependency to be declared in the POM file like any other dependency.
Of course, if you can you should add the JAR to the Central Repository.
Note: before you begin, make sure the license of the software allows you to publish it, because you are going to make the software publicly available.
Create a GitHub repository
Start with creating a GitHub repository that will become your personal Maven repo. This will be visible in the URL of the Maven repository. I use the name
Clone the GitHub repository to your computer.
Place the JAR file in the local Git repository by letting Maven perform an install:
mvn install:install-file -DgroupId=[group-id] -DartifactId=[artifact-id] -Dversion=[version] -Dpackaging=[packaging-format] -Dfile=[path-to-file] -DlocalRepositoryPath=[path-to-git-repo]
[packaging-format]define the Maven properties of the file to install.
[path-to-file]is the path to the JAR file to install.
[path-to-git-repo]is the path to the local Git repository on your computer.
After successful execution of the command a folder structure is created in the local Git repository. This structure and the files in it make it usable as a Maven repo.
Commit & Publish
Commit the changes, that were made by executing the Maven install command, to the local Git repository.
Publish the updated repository to GitHub. The JAR file is now ready to be used in a Maven POM file.
Add the GitHub repository to the POM file of the project:
<repository> <id>git-[username]</id> <name>[username]'s Git based repo</name> <url>https://github.com/[username]/[repo-name]/raw/master/</url> </repository>
[username]is your GitHub user name
[repo-name]is the name of the GitHub repository you created.
If the POM file does not include a definition of repositories, put the XML above inside a
name of the repository is not important, so use different values if you want. Just make sure the
id is unique.
Declare the dependency in the POM as you do for every dependency.
That's it! Maven should now be able to use the JAR file.