Skip to content

Maven local JAR dependency installation

Maven local JAR dependency installation allows developers to include JAR files that are not available in public repositories (such as the Maven Central Repository) into a project's build lifecycle.^[600-developer__java__3-party__java-maven01.md]

There are two primary methods to achieve this: installing the artifact to the local repository cache or referencing the file directly via the system scope.

Installation to Local Repository

The standard method involves installing the local JAR file into the user's local Maven repository (typically located at ~/.m2/repository). This makes the dependency available to the project just like any other dependency fetched from a remote server.

This process is executed using the mvn install:install-file command.^[600-developer__java__3-party__java-maven01.md]

Command Syntax

The command requires defining the coordinates (Group ID, Artifact ID, Version) and the path to the file.

mvn install:install-file -Dfile={Path/to/your/ojdbc6.jar} -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar

POM Configuration

Once the artifact is installed, it can be referenced in the pom.xml using standard dependency coordinates without needing to specify a file path.^[600-developer__java__3-party__java-maven01.md]

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0</version>
</dependency>

System Scope Dependency

Alternatively, a JAR can be referenced directly from the project's file system using the system scope.^[600-developer__java__3-party__java-maven01.md] This approach does not require installing the file to the local Maven cache, but it hardcodes a specific path within the project structure.

POM Configuration

To use this method, the dependency's <scope> must be set to system, and the physical path to the JAR must be provided in the <systemPath> element.^[600-developer__java__3-party__java-maven01.md]

<dependency>
    <groupId>com.sample</groupId>
    <artifactId>sample</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/yourJar.jar</systemPath>
</dependency>
  • Maven
  • [[Dependency Management]]
  • [[Java Build Lifecycle]]

Sources

^[600-developer__java__3-party__java-maven01.md]