How to include custom library into maven local repository

If you’ve ever wondered whether you can upload your own libraries as a dependency using Maven, the answer is yes, you can. And it is really simple.

It’s a 2-step process.

java-featured-image

Step 1

Navigate to your Maven project path in the command line and to upload a library, that’s the structure of the maven command:

mvn install:install-file
-Dfile=<path-to-file> 
-DgroupId=<group-id> 
-DartifactId=<artifact-id> 
-Dversion=<version> 
-Dpackaging=<packaging>
Using the template above, simply populate the fields that correspond to your library.
Dfile => the path to the file
groupdId, artifactId and version are entirely up to you.
Dpackaging => the package type, a.k.a. jar, war, etc.




Step 2

After you have specified a library to be included using the command above, you need to add the dependency into the dependencies tab.

<dependency>      
<groupId>group-id</groupId>      
<artifactId>artifact-id</artifactId>      
<version>version</version>      
<type>jar</type> 
</dependency>

After you have added it as a dependency, simply build the project using mvn package and boom, you have added a custom library to your Maven project.

2 2 votes
Article Rating
guest
0 Comments
Inline Feedbacks
View all comments