Monday, February 10, 2014

Include Custom Library Into Maven Local Repository

Most java developers familiar with Maven which is innovative software project management tool. Simply this maven tool capable of manage your java project jar file dependencies using a global jar repository. We only need to maintain a pom file which includes all the need jar file dependencies.

Most of the people know what mention above, but very few people know how to add a custom jar file to the maven repository. It's easy as cake.

Please follow below easy steps,

(1) Download or create your own jar file and save it in your pc.

(2) Use below command in the command line, make sure your mvn classpath configuration completes before this step.

mvn install:install-file -Dfile=c:\{your jar file name}-{version}.jar -DgroupId={package name} -DartifactId={name} -Dversion={version} -Dpackaging=jar

find below example,
Let's say we have a jar file called pdf_writer.jar

mvn install:install-file -Dfile=c:\{your jar file name}>-{version}.jar -DgroupId={package name} -DartifactId={name} -Dversion={version} -Dpackaging=jar

if you execute this command successfully, maven gives you a successful message on the console.

(3) Now last step, Update the pom xml file.

<dependency>
      <groupId>com.starfish.pdf</groupId>
      <artifactId>pdf_writer</artifactId>
      <version>1.2</version>
</dependency>

That's all we have to do, Now we can retrieve the jar dependency for our pdf writer from our maven repository.

If you interested visit Apache maven documentation for more details.

Comment below if you have any questions or any idea, If you enjoy this Please leave a comment...

Cheers !!!


No comments:

Post a Comment