Maven adds dependencies to local jar packages

Maven adds dependencies to local jar packages

use two methods

One is to use the idea tool to directly package the written project using the "Install" command and then install it into the local library; the other
is to install it into the local library through the local cmd command.

Package the written method or project, use the idea tool to package it directly and put it into the local maven warehouse

image-20230114145638328

During the packaging process, the path of the package will be output on the console, and then follow the path to find the location just packaged.

image-20230114145909730

Reference the package and add dependencies directly to the pom in the new project

<dependency>
    //文件夹名
    <groupId>org.example</groupId>
    //包名
    <artifactId>myutils</artifactId>
    <version>1.0</version>
</dependency>

test

public class Tsetmytuils {
    
    
    public static void main(String[] args) {
    
    
        Mypf my = new Mypf();
        System.out.println(my.pf(33));//1089
    }
}

image-20230114150354845

Use cmd to package in the command console and put it into the local warehouse

First find the file package and copy it out. Put it here on the E drive

image-20230114152535657

Then open cmd in the search box of the E disk and enter the following command

Among them, DgroupId can be changed by itself, so that it can be found in the warehouse

mvn install:install-file -Dfile=myutils-1.0.jar -DgroupId=org.example -DartifactId=myutils -Dversion=1.0 -Dpackaging=jar

execution succeed

image-20230114153849004

View in local maven repository

image-20230114153950066

Test: Click Refresh in the test project just now, and then it will be loaded without error

cDgw0R-1673682572535)]

Test: Click Refresh in the test project just now, and then it will be loaded without error

image-20230114154147620

Guess you like

Origin blog.csdn.net/qq_59088934/article/details/128685920