How to include library into Maven local repository

  • 06 July 2017
  • ADM

 

How to include library into Maven local repository - images/logos/maven.jpg

 

Sometimes you need to add a new dependency to your maven project, but is not available on public repositories. You can easily add the dependency to the local

For this tutorial I will use SWT library (a Java desktop gui cross-platform with native operating system look like - is the base library used for Eclipse IDE). Download the version that applies to your operating system.

Install

The command used is mvn install:install-file. The command is the same for all operating systems.

mvn install:install-file -Dfile=your-artifact-1.0.jar \
                         [-DpomFile=your-pom.xml] \
                         [-Dsources=src.jar] \
                         [-Djavadoc=apidocs.jar] \
                         [-DgroupId=org.some.group] \
                         [-DartifactId=your-artifact] \
                         [-Dversion=1.0] \
                         [-Dpackaging=jar] \
                         [-Dclassifier=sources] \
                         [-DgeneratePom=true] \
                         [-DcreateChecksum=true]

From the archive downloaded from SWT website I will use swt.jar and src.zip file and the command for this will be:

mvn install:install-file -Dfile=swt.jar -Dsources=src.zip -DgroupId=org.eclipse -DartifactId=swt -Dversion=4.6 -Dpackaging=jar -DgeneratePom=true -DcreateChecksum=true

The installation output will be similar with:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
[INFO] Installing /Volumes/data/Repositories/libs/swt-macos-x64/swt.jar to /Users/adm/.m2/repository/org/eclipse/swt/4.6/swt-4.6.jar
[INFO] Installing /var/folders/vk/q_z8wvgx5mj5bl1s3svns_lc0000gn/T/mvninstall2762162975424355891.pom to /Users/adm/.m2/repository/org/eclipse/swt/4.6/swt-4.6.pom
[INFO] Installing /Volumes/data/Repositories/libs/swt-macos-x64/src.zip to /Users/adm/.m2/repository/org/eclipse/swt/4.6/swt-4.6-sources.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.713 s
[INFO] Finished at: 2016-04-05T21:16:50+01:00
[INFO] Final Memory: 5M/123M
[INFO] ------------------------------------------------------------------------

If you see something similar you successfully install the library.

Usage

Now you just need to add the dependency to the pom.xml file.

<dependency>
    <groupId>org.eclipse</groupId>
    <artifactId>swt</artifactId>
    <version>4.6</version>
</dependency>

 

References