Maven: add a dependency to a JAR by relative path with systemPath
Codemia Knowledge Hub ·
To depend on a JAR by relative path, declare it in pom.xml with <scope>system</scope> and point <systemPath> at the file using ${project.basedir}. This works for quick tests and development, but installing the JAR into a repository with mvn install:install-file is usually the better long-term option.
Maven normally resolves dependencies from a local or remote repository. A relative-path JAR comes up with proprietary libraries or pre-release builds that are not published anywhere, and Maven was not really designed for it.
Declaring a system-scoped dependency
Dependencies go in the <dependencies> section of pom.xml, the XML file (Project Object Model) that holds the project's build configuration. For a JAR on disk, use system scope and give the path in the systemPath element:
Maven then looks for the JAR relative to the project's base directory (for example ./libs/example-jar-1.0.jar). ${project.basedir} is the directory that contains pom.xml.
| Attribute | Description | Example |
groupId | The group ID of the project. | com.example |
artifactId | The ID of the artifact (project). | example-jar |
version | The version of the artifact. | 1.0 |
scope | Scope of the dependency usage. | system |
systemPath | Path to the JAR on the local file system. | ${project.basedir}/libs/example-jar.jar |
Why system scope is discouraged
System dependencies make builds less portable, because the JAR must exist at the same location on every machine that builds the project. They also get hard to manage in large projects or when the JAR changes often. Alternatives:
- Install the JAR into your local repository with Maven's
install-filegoal. The library then behaves like any other Maven artifact. - Deploy it to a private or in-house repository. For teams and larger projects, this lets the artifact be managed like every other dependency.
Installing the JAR with install-file
After this, declare the dependency in pom.xml normally, without a system path.
Related reading
- Maven and Spring Boot - non resolvable parent pom - repo.spring.io Unknown host
- Maven best way of linking custom external JAR to my project?
- Maven clean install Failed to execute goal org.apache.maven.pluginsmaven-resources-plugin3.2.0resources
- Maven compile with multiple src directories
- Maven dependencies are failing with a 501 error
- Maven dependency for Servlet 3.0 API?
- Maven does not find JUnit tests to run
- Maven Failed to read artifact descriptor
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.