[Breaking Tips] Manually install the jar package to the Maven local repository

1. Download the jar package


Take Alipay sdk as an example:https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java/4.33.12.ALL

Insert image description here

Later, when you execute the mvn install command (that is, the installation command, life cycle: compilation, testing, packaging, installation), you will also refer to this dependency coordinate:

<!-- https://mvnrepository.com/artifact/com.alipay.sdk/alipay-sdk-java -->
<dependency>
    <groupId>com.alipay.sdk</groupId>
    <artifactId>alipay-sdk-java</artifactId>
    <version>4.33.12.ALL</version>
</dependency>

Then drop the downloaded jar package into the specified directory. Here I will put it in the maven bin directory.

Insert image description here


2. In the jar package directory, open the command line window and execute the following command:


mvn install:install-file -DgroupId=com.alipay.sdk -DartifactId=alipay-sdk-java -Dversion=4.33.12.ALL -Dpackaging=jar -Dfile=alipay-sdk-java-4.33.12.ALL.jar

Detailed explanation of parameters:

  • mvn install:install-fileIt is a command provided by Maven for installing local jar packages into the local Maven repository.

  • DgroupId=com.alipay.sdk: Specify the groupId of the jar package. In Maven, groupId is used to identify the organization or institution of the project, usually in reverse domain name format.

  • DartifactId=alipay-sdk-java:Specify the artifactId of the jar package. In Maven, artifactId is the unique identifier of the project and is used to uniquely identify a project. (Item name)

  • Dversion=4.33.12.ALL: Specify the version number of the jar package. In Maven, version is used to identify the version of the project.

  • Dpackaging=jar: Specify the packaging method of the jar package. Here, the jar packaging method is used.

  • Dfile=D:\Program Files\Environment\apache-maven-3.6.1\bin\alipay-sdk-java-4.33.12.ALL.jar: Specify the local file path of the jar package to be installed. Here, the path of the jar package is D:\Program Files\Environment\apache-maven-3.6.1\bin\alipay-sdk-java-4.33.12.ALL.jar.

After executing this command, Maven will copy the jar package in the specified path to the local Maven repository and generate the corresponding pom.xml file. In this way, we can reference the jar package in the pom.xml file of the Maven project and perform project building and dependency management.


As shown in the figure below, it appearsBUILD SUCCESSIndicates that the dependency installation is successful.

Insert image description here

Next we go to the maven repository to view the dependencies we just installed:

Insert image description here

OK, you're done. If the development tool cannot refresh the maven dependency, you can temporarily use this method to solve it. Or some dependent jar packages are not open source, which can also be solved using this method.

Guess you like

Origin blog.csdn.net/qq_46921028/article/details/131420262