How to add a local lib directory to Maven

March 18th, 2010 by
Sometimes there is a dependency not available at a remote repository and one is too lazy to set up a local maven repository – that’s when one adds a directory in the project structure and wants maven to find dependencies there.
  1. Create a directory called “lib” in the project root
  2. Add the following markup to the pom.xml inside the <repositories>-Tag (create if it does not exist):
    <repository>
        <id>lib</id>
        <name>lib</name>
        <releases>
            <enabled>true</enabled>
            <checksumPolicy>ignore</checksumPolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <url>file://${project.basedir}/lib</url>
    </repository>
  3. Assuming you’ve got a jar file with artifactId=mylibrary, groupId=com.hascode.plugin and a version=1.0.0 you should first rename your jar file to artifactId-version.jar – in the given example this would be mylibrary-1.0.0.jar
  4. In the next step you should create a specific directory structure in your lib folder : Create a sub directory for each part of your groupId, then inside a directory named after the artifactId and inside of this one a directory named after the version. Put the jar in this last directory!
    mkdir -p com/hascode/plugin/mylibrary/1.0.0
    lib
    `-- com
        `-- hascode
            `-- plugin
                `-- mylibrary
                    `-- 1.0.0
                        `-- mylibrary-1.0.0.jar
  5. You should now be able to build your project with the bundled dependency .. if you’re using the Maven Eclipse Plugin a refresh of the Maven configuration might be needed…

Tags: , , , , ,

Leave a Reply

Please note, that no personal information like your IP address is stored and you're not required to enter you real name.

Comments must be approved before they are published, so please be patient after having posted a comment - it might take a short while.

Please leave these two fields as-is:
Search
Categories