Home > Java > javaTutorial > How to Add a JAR Dependency via Relative Path in Maven?

How to Add a JAR Dependency via Relative Path in Maven?

Susan Sarandon
Release: 2024-12-29 04:00:14
Original
979 people have browsed it

How to Add a JAR Dependency via Relative Path in Maven?

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:

  1. Declare a local repository:

    <repositories>
      <repository>
        <id>my-local-repo</id>
        <url>file://${project.basedir}/my-repo</url>
      </repository>
    </repositories>
    Copy after login
  2. 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>
    Copy after login
  3. Declare the dependency in your pom.xml:

    <dependency>
      <groupId>your.group.id</groupId>
      <artifactId>3rdparty</artifactId>
      <version>X.Y.Z</version>
    </dependency>
    Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template