Add a local jar package to maven and a jar package to maven

Source: Internet
Author: User

Add a local jar package to maven and a jar package to maven

Today, I met a jar package that is not in the mavan warehouse, so I can only add a local jar package. It took a lot of time to find information and finally OK. Therefore, it is recorded here.

1. For the first time, you can use <systemPath> to solve the problem on the Internet, as shown below:

<dependencies>  <dependency>    <groupId>xxx</groupId>    <artifactId>xxx</artifactId>    <version>xxx</version>    <scope>system</scope>    <systemPath>${basedir}/xx.jar</systemPath>  </dependency></dependencies>

However, when running jetty and packaging, you cannot find the referenced package and pass it directly. Maven is not familiar with all kinds of pain points. I went to the maven official website and read the document. After a while, I finally found a solution:

2. Create a local repository and install it in the form of plugin:

(1) create a local repository:

<repositories>  <repository>    <id>local-repo</id>    <url>file://${basedir}/repo</url>  </repository></repositories>

(2) install the local library to maven:

mvn install:install-file -Dfile=<jar-path> -DgroupId=<group> -DartifactId=<artifactId> -Dversion=<version> -Dpackaging=<packaging> -DlocalRepositoryPath=<path>

(Note: parameter description: jar-path is the path of your jar, group, artifactId, and version. packaging is jar or war, dlocalRepositoryPath is the path of the local repository you created earlier ).

(3) installation as a plug-in:

<plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-install-plugin</artifactId>    <version>2.4</version>    <executions>        <execution>            <phase>initialize</phase>            <goals>                <goal>install-file</goal>            </goals>            <configuration>                <groupId>xxx</groupId>                <artifactId>xxx</artifactId>                <version>xxx</version>                <packaging>jar</packaging>                <file>${basedir}/xxx.jar</file>            </configuration>        </execution>    </executions></plugin>

(4) add dependency:

<dependency>    <artifactId>xxx</artifactId>    <groupId>xxx</groupId>    <version>xxx</version></dependency>

OK. This is OK. Because I am not familiar with maven, I did spend a lot of time reading documents. Here, I will take a note and hope to help people who encounter the same problem.

 

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.