DEV Community

Victor Cardoso Higino
Victor Cardoso Higino

Posted on

Maven: How to use local lib

Sometime ago I saw me before a situation that I've never had passing before. I needed use my local lib on Java maven project.

To do that I followed the steps:

Step One: Put in my local library into maven repository

mvn install:install-file -Dfile=home/victor/dev/Example.jar -DgroupId=br.com.example -DartifactId=Example -Dversion=1.0.0 -Dpackaging=jar
Enter fullscreen mode Exit fullscreen mode

Step Two: Install maven dependencies

mvn clean install
Enter fullscreen mode Exit fullscreen mode

Step Three: Use the library in the project

Add the pendency in the pom.xml file like that:

<dependencies>
  ...
  <dependency>
    <groupId>br.com.example</groupId>
    <artifactId>Example</artifactId>
    <version>1.0.0</version>
  </dependency>
  ...
</dependencies>
Enter fullscreen mode Exit fullscreen mode

That's it!

I hope this helps you.

Top comments (3)

Collapse
 
khmarbaise profile image
Karl Heinz Marbaise

Hm...if your local library is a maven project you can simply do that via: mvn clean install if your local library is NOT a maven project then you are right. What I don't understand is the step two... Install maven dependencies?

Collapse
 
victorcardosohigino profile image
Victor Cardoso Higino

Hi Karl.
Alter you put your local lib in local maven repository you can execute mvn clean install to use the lib.
The Install maven dependencies isn't line command.

Collapse
 
renatoaraujow profile image
Renato Araújo

Very good! Congrats.