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.