Maven system scope dependency¶
In Apache Maven, the system scope is a dependency scope used to include artifacts that are physically present on the local file system of the machine, rather than resolving them from a remote or local repository like Maven Central.^[600-developer__java__3-party__java-maven01.md]
Configuration¶
To define a system-scoped dependency, the pom.xml file must explicitly set the <scope> element to system and provide the path to the file using the <systemPath> element^[600-developer__java__3-party__java-maven01.md].
A common convention for the path is to place the JAR file within the project directory (e.g., src/main/resources) and reference it using the ${project.basedir} property^[600-developer__java__3-party__java-maven01.md].
Example¶
The following configuration demonstrates how to reference a local JAR file named yourJar.jar using the system scope:
<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>
^[600-developer__java__3-party__java-maven01.md]
Comparison with Local Repository Installation¶
While the system scope allows for direct file references, an alternative approach is to install the JAR file manually into the local Maven cache using the mvn install:install-file command^[600-developer__java__3-party__java-maven01.md].
This installation method assigns a specific groupId, artifactId, and version to the file, allowing it to be treated as a standard dependency (usually with the default compile scope) rather than a system-scoped one^[600-developer__java__3-party__java-maven01.md].
Example: Installing Oracle JDBC¶
mvn install:install-file \
-Dfile={Path/to/your/ojdbc6.jar} \
-DgroupId=com.oracle \
-DartifactId=ojdbc6 \
-Dversion=11.2.0 \
-Dpackaging=jar
^[600-developer__java__3-party__java-maven01.md]
Once installed, the dependency can be declared in the pom.xml without a systemPath, behaving like a standard transitive dependency^[600-developer__java__3-party__java-maven01.md].
Sources¶
600-developer__java__3-party__java-maven01.md