Two ways Maven uses a third-party jar file to go

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.