Add a jar file to the local Maven library and add a jar file to maven

Source: Internet
Author: User

Add a jar file to the local Maven library and add a jar file to maven

Sometimes the maven dependency we want to use cannot be found in the official repo library. However, we have obtained all jar files in the dependency from other channels. This article records how to add jar files to the local library.

There are three methods from complexity to Simplicity:

The first method is helpful for team development. I plan to record it with an article. Here we will introduce two other methods:

 

Run the command mvn install: install-file to install the jar file to the local repository.

Syntax specification:

 mvn install:install-file    -Dfile=<path-to-file>    -DgroupId=<group-id>    -DartifactId=<artifact-id>    -Dversion=<version>    -Dpackaging=<packaging>    -DgeneratePom=true    Where: <path-to-file>  the path to the file to load         <group-id>      the group that the file should be registered under         <artifact-id>   the artifact name for the file         <version>       the version of the file         <packaging>     the packaging of the file e.g. jar

Take the document <not-yet-commons-ssl-0.3.17.jar> as an example:

 mvn install:install-file  -Dfile=e:\not-yet-commons-ssl-0.3.17.jar  -DgroupId=org.apache.commons  -DartifactId=not-yet-commons-ssl  -Dversion=0.3.17  -Dpackaging=jar  -DgeneratePom=true

 

Import data through the project pom configuration file

Edit the project pom file, add an entry to the dependency, and specify <scope> and <systemPath>.

Or the file <not-yet-commons-ssl-0.3.17.jar> as an example:

 <dependency>    <groupId>org.apache.commons</groupId>    <artifactId>not-yet-commons-ssl</artifactId>    <version>0.3.17</version>    <scope>system</scope>    <systemPath>e:\not-yet-commons-ssl-0.3.17.jar</systemPath></dependency>

Wait. A warning is displayed after compilation:

[WARNING] 'dependencies.dependency.systemPath' for org.apache.commons:not-yet-commons-ssl:jar should use a variable instead of a hard-coded path e:\not-yet-commons-ssl-0.3.17.jar @ line 35, column 16
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.

It turned out that maven told us not to use absolute paths such as C: \ Windows, but to use $ {java. the relative path (variable) such as home}, otherwise it reduces compilation reproducibility and threatens us to not support this method in the future.

Well, we can create a maven repository environment variable to eliminate this warning if you think it is necessary.

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.