Maven local JAR dependency¶
Maven local JAR dependency refers to the inclusion of JAR files located on the local file system into a Maven project, rather than fetching them from a central or remote repository^[600-developer-java-3-party-java-maven01.md]. This is a common practice when dealing with proprietary libraries, such as specific database drivers, that are not publicly available in the Maven Central Repository^[600-developer-java-3-party-java-maven01.md].
There are two primary methods to achieve this: installing the JAR to the local repository cache or referencing it directly via the system scope^[600-developer-java-3-party-java-maven01.md].
Methods¶
Installing to Local Repository¶
The standard method to make a local JAR available to a Maven project is to install it into the user's local Maven repository (typically located at ~/.m2/repository)^[600-developer-java-3-party-java-maven01.md]. This allows the dependency to be treated like any other library retrieved from a remote server.
This requires executing the mvn install:install-file command with parameters specifying the file location and the Maven coordinates to be assigned to it^[600-developer-java-3-party-java-maven01.md].
For example, to install an Oracle JDBC driver (ojdbc6.jar), the following command is used^[600-developer-java-3-party-java-maven01.md]:
mvn install:install-file -Dfile={Path/to/your/ojdbc6.jar} -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0 -Dpackaging=jar
Once installed, the dependency can be declared in pom.xml using standard coordinates^[600-developer-java-3-party-java-maven01.md]:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
</dependency>
Using System Scope¶
Alternatively, a JAR can be referenced directly from a specific path within the project structure using the system scope^[600-developer-java-3-party-java-maven01.md]. This method does not require installing the artifact to the local Maven cache.
To use this approach, the dependency must be configured with <scope>system</scope> and a <systemPath> pointing to the file location^[600-developer-java-3-party-java-maven01.md]. Project properties like ${project.basedir} can be used to define relative paths^[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>
Related Concepts¶
- [[Apache Maven]]
- [[Maven Build Lifecycle]]
- [[Dependency Management]]
Sources¶
600-developer-java-3-party-java-maven01.md