Sometimes when the required libraries / dependencies is not available in the Maven Central Repository we need to manually install it to our local repository. This library must be placed in the correct directory in our local repository to enable Maven to find it. The default location is under the ${user.home}/.m2/repository
.
To make this job easier Maven provides a maven-install-plugin
that will help us to install the third-party library in the correct place. The following command shows how to do it.
The long command
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
Where:
-Dfile
= path to the third-party library file-DgroupId
= thegroupId
of the library-DartifactId
= theartifactId
of the library-Dversion
= theversion
number of the library-Dpackaging
= the library packaging
An example to install an Oracle JDBC library to your local repository is:
mvn install:install-file -Dfile=ojdbc7.jar -DgroupId=com.oracle \
-DartifactId=ojdbc7 -Dversion=12.1.0.2 -Dpackaging=jar
The simple command
If you have the pom.xml
file, you can install it with the following command:
mvn install:install-file \
-Dfile=<path-to-file> \
-DpomFile=<path-to-pomfile>
Where:
-Dfile
= path to the third-party library file-DpomFile
= the location to the librarypom.xml
file
Starting with the Maven version 2.5 you can use even a simpler command. When the library is build by Maven, a pom.xml
file will be placed under the META-INF
directory. This pom.xml
file will be used by default when we install the library. To install a library all you need is the following command:
mvn install:install-file -Dfile=<path-to-file>
- How do I build simple search page using ZK and Spring Boot? - March 8, 2023
- How do I calculate days between two dates excluding weekends and holidays? - January 12, 2023
- How do I discover the quarter of a given date? - January 11, 2023
Any suggestions?
Hi Richard, to install a library use the
install
goal, so the right commandmvn install:install
and notmvn install:JMapView
.