How to create and use local JAR file as a local Maven dependency
Posted By : Ravindra Singh | 16-Sep-2018
Introduction:
Sometimes you want to work with a JAR file that is not hosted in Maven Central, So In this article, we are going to describe some different ways you can install and work with local dependency JAR file within your local Maven setup into .m2 folder repository. Apache Maven is a software project management tool, That is used to help in the management of the project builds, Documentation and Dependencies.
Now, In order to set up the maven local JAR file just follow the below steps:
>> First you will create your project JAR file as :
1. The first step is to Download as a zip file or clone the project from GitHub, for that you want to make the JAR file to use as a local maven Dependency.
Example: Binance is a third party API that is used to provide Market data information, But Binance API dependency is not available on Maven Central so If we want to use Binance API dependency as a local JAR file into our project then follow the below steps.
2. Unzip the downloaded project into your local system drive.
3. Import the unzip project file into your Eclipse IDE.
4. And then Run the project as maven build, then there is Edit configuration window is open, now what you will do you just enter the "clean package" in Goal field of an open window and then run the project.
5. Now if your build is successful, you will get the message on eclipse console build success.
6. And your .jar file is stored in the target folder of your project local repository.
1
2
3
4
5
6
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
1
2
3
4
5
6
mvn install:install-file \
-Dfile=target/binance-api-dependencies.jar \
-DgroupId=com.example.demo \
-DartifactId=Binance-api \
-Dversion=1.0.9 \
-Dpackaging=jar
< path-to-file >: the path of the target folder from where we load JAR file e.g -> c:\projectName/target/binance-api-1.0.9.jar
< group-id >: the group is the name of your project package Name e.g -> com.example.demo
< artifact-id >: the artifact name for the file is the name of dependency class you want to have e.g -> Binance-api
< version >: the version number of dependecy e.g -> 1.0.9
< packaging >: the packaging of the file you want to create e.g. -> jar
mavenLocal()
mavenCentral artifactUrls:["file:/home/ravindrasingh/.m2/repository/"]
1
2
3
4
5
6
7
8
9
10
11
repositories {
mavenCentral()
mavenLocal()
mavenCentral artifactUrls:["file:/home/ravindrasingh/.m2/repository/"]
//maven { url "https://staging.myproject.com/maven-libs" }
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
1
compile group: 'com.example.demo', name: 'binance-api', version: '1.0.9'
maven { url "https://staging.myproject.com/maven-libs" }
//mavenLocal()
//mavenCentral artifactUrls:["file:/home/ravindrasingh/.m2/repository/"]
repositories {
mavenCentral()
//mavenLocal()
//mavenCentral artifactUrls:["file:/home/ravindrasingh/.m2/repository/"]
maven { url "https://staging.myproject.com/maven-libs" }
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Ravindra Singh
Ravindra is Sr. Associate Consultant Development- Java (Backend Developer). And Familiar with AWS Cloud Machine Learning Programming (AWS Lex, Lambda, Polly, Elasticsearch ), And also having good experience in Spring Boot Microservice Architecture Applica