Ernest is a Java developer. Outside programming, he also enjoys a wide variety of hobbies which includes sky-diving, photography, exercising and listening to music.

In my previous article I wrote, we went through a step by step process of creating a GitHub account and hosting our Maven artifact on it. In this article, I will show you how to use that artifact we hosted on GitHub as a dependency in a new maven project.

At this stage i take it as you already have your artifact already hosted on GitHub. If not, you can follow this article to learn how to do so.

Steps to how to use GitHub hosted Maven artifact in a Maven Project

Create a new Maven Java Application. I will be using NetBeans for this tutorial.

<!--?xml version="1.0" encoding="UTF-8"?--> 4.0.0 com.mycompany TestMaven 1.0-SNAPSHOT jar UTF-8 1.7 1.7 <!--?xml version="1.0" encoding="UTF-8"?--> 4.0.0 com.mycompany TestMaven 1.0-SNAPSHOT jar UTF-8 1.7 1.7

Now in your POM, we have to specify where our GitHuB repository is and also all dependencies. To do so, edit the xml below and paste after the closing properties tag.

{GIT-USERNAME} {NAME-OF-GIT-REPOSITORY} {GIT-REPOSITORY-URL} {GROUP-ID-OF-ARTIFACT} {NAME-OF-ARTIFACT} {VERSION-NUMBER} compile {GIT-USERNAME} {NAME-OF-GIT-REPOSITORY} {GIT-REPOSITORY-URL} {GROUP-ID-OF-ARTIFACT} {NAME-OF-ARTIFACT} {VERSION-NUMBER} compile

In my case, this should be

<!--?xml version="1.0" encoding="UTF-8"?--> 4.0.0 org.jpedalh TestMaven 1.0-SNAPSHOT jar UTF-8 1.7 1.7 moshhasa maven-test-repo https://github.com/moshhasa/maven-test-repo/raw/master/ org.jpedal FooBar 1.0 compile <!--?xml version="1.0" encoding="UTF-8"?--> 4.0.0 org.jpedalh TestMaven 1.0-SNAPSHOT jar UTF-8 1.7 1.7 moshhasa maven-test-repo https://github.com/moshhasa/maven-test-repo/raw/master/ org.jpedal FooBar 1.0 compile

Now save the Pom file and do a Clean and Build on your project. You should see Maven downloading your artifact from GitHub.This will me saved in your local repository.

Did you know...

IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?

It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page