Site iconJava PDF Blog

How to use GitHub hosted Maven artifact in NetBeans IDE

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.

Give it a Project Name, Group Id and Version, click here to learn more about Maven projects I will call mine TestMven and leave the rest as default.

Once done, right click on the project and select Open POM. You should see something like this.

    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
    
     

In my case, this should be


    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.

Once done, Open the Dependencies folder in the Projects view and you should see the jar added to your project.

Now Test Your Dependency.

Hopefully you have found this quick guide useful. In my next article i will show you how I converted the Ant NetBeans Plugin to Maven Plugin