Adding a Dependency to a Jar by Relative Path in Maven
Problem:
You want to add a proprietary jar as a dependency to a Maven project, but without adding it to a repository or requiring developers to do so manually. Your goal is to reference the jar from a relative path within your project's source control.
Solution:
You can use a "file repository" local to your project and a dependency declaration without the system scope.
Steps:
Declare a local repository:
<repositories> <repository> <id>my-local-repo</id> <url>file://${project.basedir}/my-repo</url> </repository> </repositories>
Install the jar using the install:install-file goal with the localRepositoryPath parameter:
mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file \ -Dfile=<path-to-file> -DgroupId=<myGroup> \ -DartifactId=<myArtifactId> -Dversion=<myVersion> \ -Dpackaging=<myPackaging> -DlocalRepositoryPath=<path>
Declare the dependency in your pom.xml:
<dependency> <groupId>your.group.id</groupId> <artifactId>3rdparty</artifactId> <version>X.Y.Z</version> </dependency>
By using this method, you can add the proprietary jar as a dependency and link to it from a relative path within your project, without relying on a repository or requiring developers to take additional steps.
The above is the detailed content of How to Add a JAR Dependency via Relative Path in Maven?. For more information, please follow other related articles on the PHP Chinese website!