In Maven, using a third-party library typically downloads the library from a remote repository through the dependency defined in the Pom.xml file. However, if the library file is a library within the company, or if it is local and cannot be downloaded through remote repository, there are two ways to meet the requirements.
Method One:
To install the local jar file into the local repository, follow these steps:
1. Prepare the local jar file.
2. Install the jar file using the following command
MVN Install:install-file-dfile=abc.jar
-dgroupid=com.mycompany.myproduct-dartifactid=abc
-dversion=1.0-dpackaging=jar-dgeneratepom=True
Where-dfile formulates the location of the jar file. After executing the command, a directory (COM) appears in the local repository (usually the $home/.m2 directory), under which there is a Abc-1.0.jar file and an automatically generated pom file.
3. After installation, when using it in another application, just specify the appropriate dependency in the Pom file, such as:
<dependencies>
<dependency>
<groupId>com.mycompany.myproduct</groupId>
<artifactId>abc</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
Method Two:
This method differs from the previous method in that it does not install any library files, but only specifies the directory of the jar files in the Pom file in the application
, the following settings are available in the dependency in the POM:
<dependencies>
<dependency>
<groupId>com.mycompany.myproduct</groupId>
<artifactId>abc</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>/home/root/abc.jar</systemPath>
</dependency>
</dependencies>
The scope is set to system, the default is compile, indicating that dependency is not to go to repository to find, but in the system directory
Find in. SYSTEMPATH specifies the absolute path to the jar file.
Two ways Maven uses a third-party jar file to go