大家肯定遇到过想在pom文件中加入自己开发的依赖包,这些包肯定是不是在Maven仓库(http://repo1.maven.org/maven2/)的。那我们怎么将那些不存在Maven仓库中的包加入到本地的Maven库中呢?很简单。这里以IKAnalyzer.jar包为例进行讲解。
第一步:将IKAnalyzer.jar包存放在一个文件夹中,比如mylib文件夹
第二步:建立一个IKAnalyzer.jar包相关的pom.xml文件,需要在pom.xml文件中定义其maven坐标及其相应的依赖代码即可,同样将pom文件存放在上述jar文件同一文件夹下,IKAnalyzer.jar坐标及依赖代码如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.wltea.ik-analyzer</groupId> <artifactId>ik-analyzer</artifactId> <version>3.2.8</version> <name>IK Analyzer 3</name> <description>A dictionary and grammar-based Chinese segmenter</description> <dependencies> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> <version>3.0.3</version> <optional>true</optional> </dependency> <dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-core</artifactId> <version>1.4.1</version> <optional>true</optional> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.2</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-analyzers</artifactId> <version>3.0.3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-smartcn</artifactId> <version>3.0.3</version> <scope>test</scope> </dependency> </dependencies> </project>
mvn install:install-file \ -Dfile=IKAnalyzer3.2.8.jar \ -DgroupId=org.wltea.ik-analyzer \ -DartifactId=ik-analyzer \ -Dversion=3.2.8 \ -Dpackaging=jar
<dependency> <groupId>org.wltea.ik-analyzer</groupId> <artifactId>ik-analyzer</artifactId> <version>3.2.8</version> </dependency>
<dependency> <groupId>org.wltea</groupId> <artifactId>IKAnalyzer</artifactId> <version>3.2.8</version> <systemPath>C:\Users\yangping\Desktop\a\IKAnalyzer3.2.8.jar</systemPath> </dependency>