Maven command to install local Jar package to Maven local repository

1 Introduction

Maven is an automated management tool for project construction and dependency management under the Java platform.

We can easily manage Jar dependency packages through the Maven remote warehouse address, but in actual projects sometimes there are Jar packages that are not in the remote warehouse, and we must use them in the project, then we need to add the local Jar to the local in the Maven repository.

2. Install the local Jar package to the Maven local repository

2.1. Maven command

  • Open cmd window in Windows environment.

  • Open Terminal in Mac environment.

  • IDEA In the Maven panel, click Execute maven Goal, as shown below:

Insert image description here

Enter the following command

mvn install:install-file -Dfile=C:/csdn/woniu.jar -DgroupId=com.csdn.demo -DartifactId=woniu-sdk -Dversion=1.2.3 -Dpackaging=jar

Parameter introduction, do not use this

# 将本地自定义 jar 安装到 maven 仓库
mvn install:install-file

# 设置文件所在的路径与文件名
-Dfile=C:/csdn/woniu.jar

# 设置 groupId 名
-DgroupId=com.csdn.demo

# 设置 artifactId 名
-DartifactId=woniu-sdk

# 设置版本号
-Dversion=1.2.3

# 设置类型,有如下值:pom、jar、war、maven-plugin。
# 但是一般常用的是jar类型
-Dpackaging=jar

2.2. Add dependencies to the project

Add the corresponding dependencies to the project's pom.xml file


<dependency>
    <groupId>com.csdn.demo</groupId>
    <artifactId>woniu-sdk</artifactId>
    <version>1.2.3</version>
</dependency>

Then reload All Maven Projects, and you can use the local Jar package just like using the Maven package.

3. One note per day

3.1. Query the websites that Maven depends on

Querying the website that Maven depends on only provides pom dependency information and provides the function of downloading jars.

Query the websites that Maven depends on

3.2. Common remote warehouse addresses used by Maven

3.2.1. Maven official operation and maintenance warehouse No. 2

<mirror>
    <id>repo2</id>
    <name>Mirror from Maven Repo2</name>
    <url>http://repo2.maven.org/maven2/</url>
    <mirrorOf>central</mirrorOf>
</mirror>

3.2.2. Maven’s warehouse in the UK

<mirror>
    <id>ui</id>
    <name>Mirror from UK</name>
    <url>http://uk.maven.org/maven2/</url>
    <mirrorOf>central</mirrorOf>
</mirror>

3.2.3. Alibaba Cloud’s remote warehouse

<mirror>
    <id>nexus-aliyun</id>
    <name>Nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>
</mirror>

3.2.4. JBoss warehouse

<mirror>
    <id>jboss-public-repository-group</id>
    <mirrorOf>central</mirrorOf>
    <name>JBoss Public Repository Group</name>
    <url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>

This tutorial ends here. If you have any questions, please feel free to discuss.

Practice is the only criterion for testing truth. One click to send three consecutive attentions to avoid getting lost.

Guess you like

Origin blog.csdn.net/u011374856/article/details/128629442