Import the outsourced jar package into the local Maven repository

1.Problem description

Sometimes we need to introduce jars that are not available online in Alibaba Cloud or mvnRespository. You need to download other people's jar packages and put them in the libs directory of your own project. This is very inconvenient. Therefore, the outsourced jar needs to be imported into the local maven warehouse. In this way, you can directly import it according to the three-element coordinates in the pom.xml file.

2. The method is as follows

mvn install:install-file -Dfile=D:/ideal_project/XXXX_Project/app-scanqrcode-signseal/platform-custService/libs/pinyin4j-2.5.0.jar \
-DgroupId=pinyin4j \ 
-DartifactId=pinyin4j \
-Dversion=2.5.0 -Dpackaging=jar \
-DgeneratePom=true \
-settings D:/software/apache-maven-3.6.3/conf/ali_settings.xml

In this way, the jar and the corresponding .pom file will be generated under the path of the local warehouse configured in ali_settings.xml, both of which are indispensable.
Insert image description here
Then introduce it in the project:

<dependency>
    <groupId>pinyin4j</groupId>
    <artifactId>pinyin4j</artifactId>
    <version>2.5.0</version>
</dependency>

In this way, when we give the project to others, we must also give the jar to others at the same time. You can put the jar package in the libs directory of the project.

There is another way to introduce outsourced jars.
In this way, there is no need to import the jar package into the local maven repository through the above command, because it is imported directly from the path we know.

 <dependency>
      <groupId>pinyin4j</groupId>
      <artifactId>pinyin4j</artifactId>
      <version>2.5.0</version>
      <scope>system</scope>
      <systemPath>${
    
    project.basedir}/libs/pinyin4j-2.5.0.jar</systemPath>
  </dependency>

Insert image description here

Guess you like

Origin blog.csdn.net/adminstate/article/details/133385051