Lib directory as repository

With simple trick you can create project's private repository in a lib directory in a Maven project. I use this way when JAR libraries cannot be found in public repositories, a example is the proprietary Oracle JDBC driver.

Firstly add new repository declaration to your project's pom.xml:

<repositories>
  <repository>
      <id>project_lib</id>
      <name>Repository in project's lib dir</name>
      <layout>default</layout>
      <url>file:///./lib</url>
  </repository>
</repositories>

Next, to install jar in the lib repo, invoke line below under project directory. Remember to fill in -Durl parameter properly.

mvn deploy:deploy-file -Durl=file:///c:/FULL_PATH_HERE/lib \
   -DrepositoryId=project_lib -Dfile=ojdbc14.jar \
   -DgroupId=com.oracle  -DartifactId=ojdbc14 \
   -Dversion=10.2.0.1 -Dpackaging=jar

Make sure that apropriate structure was created under lib directory. Finnaly you can add following dependency to project's pom.xml:

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc14</artifactId>
    <scope>runtime</scope>
    <version>10.2.0.1</version>
</dependency>

Generally for big projects it is recommended to create a shared repository for development teams, however above approach is more consistent especially when project is archived and you are not sure about durability of your shared repo.

The system scope way

If you need JAR only for build phase then there is a simpler way of adding JAR from custom directory as dependency: the system scope. It is similar to provided scope because dependencies are added to build phase classpath. In such case JARs won't be incorporated automatically to WARs, EARs etc, as it happens with compile scope. To overcome this limit I suggest using lib as repository way. Below is the example usage of system scope with lib directory.

<dependency>
    <groupId>legacy_lib</groupId>
    <artifactId>legacy_lib_for_build</artifactId>
    <scope>system</scope>
    <systemPath>${basedir}/lib/legacy_lib_for_build.jar</systemPath>
    <version>1.0</version>
</dependency>