Search code examples
javamavendependencieslibrariesmvn-repo

How to add local jar files to a Maven project?


How do I add local jar files (not yet part of the Maven repository) directly in my project's library sources?


Solution

  • Install the JAR into your local Maven repository (typically .m2 in your home folder) as follows:

    mvn install:install-file \
       -Dfile=<path-to-file> \
       -DgroupId=<group-id> \
       -DartifactId=<artifact-id> \
       -Dversion=<version> \
       -Dpackaging=<packaging> \
       -DgeneratePom=true
    

    Where each refers to:

    <path-to-file>: the path to the file to load e.g → c:\kaptcha-2.3.jar

    <group-id>: the group that the file should be registered under e.g → com.google.code

    <artifact-id>: the artifact name for the file e.g → kaptcha

    <version>: the version of the file e.g → 2.3

    <packaging>: the packaging of the file e.g. → jar

    Reference