阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

将自己开发的依赖包加入到Maven本地仓库

154次阅读
没有评论

共计 6346 个字符,预计需要花费 16 分钟才能阅读完成。

Maven 在 pom 文件中加入自己开发的依赖包,这些包肯定是不在 Maven 仓库(http://repo.maven.apache.org/maven2/)的。那我们怎么将那些不在 Maven 仓库中的包加入到本地的 Maven 库中呢?很简单。这里以 IKAnalyzer.jar 包为例进行讲解。

第一步:将 IKAnalyzer.jar 包存放在一个文件夹中,比如 test 文件夹
第二步:建一个 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>

 第三步:打开 CMD,进入到 mylib 文件夹,运行下面命令

E:\test>mvn install:install-file -Dfile= 文件名.jar -DgroupId= 组织名 -DartifactId= 项目名
-Dversion= 版本号 -Dpackaging=jar
[INFO] Scanning for projects…
[INFO]
[INFO] ————————————————————————
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ————————————————————————
[INFO]
[INFO] — maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom

Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-uti
ls/3.0.5/plexus-utils-3.0.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0.5/plexus-utils-3.0.5.pom (3 KB at 0.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-
api/2.0.6/maven-plugin-api-2.0.6.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-project
/2.0.6/maven-project-2.0.6.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-setting
s/2.0.6/maven-settings-2.0.6.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-profile
/2.0.6/maven-profile-2.0.6.jar
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-
registry/2.0.6/maven-plugin-registry-2.0.6.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-r
egistry/2.0.6/maven-plugin-registry-2.0.6.jar (29 KB at 15.4 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/classworlds/classworlds/1.1-al
pha-2/classworlds-1.1-alpha-2.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-profile/
2.0.6/maven-profile-2.0.6.jar (35 KB at 10.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-model/2
.0.6/maven-model-2.0.6.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-settings
/2.0.6/maven-settings-2.0.6.jar (48 KB at 11.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifac
t-manager/2.0.6/maven-artifact-manager-2.0.6.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-a
pi/2.0.6/maven-plugin-api-2.0.6.jar (13 KB at 2.8 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-reposit
ory-metadata/2.0.6/maven-repository-metadata-2.0.6.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-reposito
ry-metadata/2.0.6/maven-repository-metadata-2.0.6.jar (24 KB at 3.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifac
t/2.0.6/maven-artifact-2.0.6.jar
Downloaded: https://repo.maven.apache.org/maven2/classworlds/classworlds/1.1-alp
ha-2/classworlds-1.1-alpha-2.jar (37 KB at 5.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-uti
ls/3.0.5/plexus-utils-3.0.5.jar
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact
-manager/2.0.6/maven-artifact-manager-2.0.6.jar (56 KB at 6.4 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-model/2.
0.6/maven-model-2.0.6.jar (85 KB at 6.9 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact
/2.0.6/maven-artifact-2.0.6.jar (86 KB at 5.7 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-project/
2.0.6/maven-project-2.0.6.jar (114 KB at 5.8 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-util
s/3.0.5/plexus-utils-3.0.5.jar (226 KB at 10.7 KB/sec)
[INFO] Installing E:\test\ 文件名.jar to C:\Users\Administrator\.m2\repository\ 组织名 \
项目名 \ 版本号 \ 文件名.jar
[INFO] Installing C:\Users\ADMINI~1\AppData\Local\Temp\mvninstall199361744543933
8455.pom to C:\Users\Administrator\.m2\repository\ 组织名 \ 项目名
\ 版本号 \ 文件名.pom
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time: 30.436 s
[INFO] Finished at: 2016-05-21T22:16:10+08:00
[INFO] Final Memory: 9M/183M
[INFO] ————————————————————————

这样你就可以将 IKAnalyzer3.2.8.jar 安装到您 Maven 本地的库文件夹相应目录中。你可以根据你需要安装包的实际情况修改上面的几个参数的设定值即可。之后你可以在 pom.xml 文件中通过以下依赖在项目中引入上述的包,如下:
 
<dependency>
    <groupId>org.wltea</groupId>
    <artifactId>IKAnalyzer</artifactId>
    <version>3.2.8</version>
</dependency>

当然你也可以不将 IKAnalyzer3.2.8.jar 发布到您本地的 Maven 库中,而是通过下面配置引入,效果和上面的差不多:

<dependency>
    <groupId>org.wltea</groupId>
    <artifactId>IKAnalyzer</artifactId>
    <version>3.2.8</version>
    <scope>system</scope>
    <systemPath>E:\test\IKAnalyzer3.2.8.jar</systemPath>
</dependency>

Maven 构建过程详解 http://www.linuxidc.com/Linux/2016-03/129432.htm

利用 GitHub 搭建个人 Maven 仓库 http://www.linuxidc.com/Linux/2016-04/130197.htm

使用 Maven 在 NetBeans 下构建 Wicket 项目 http://www.linuxidc.com/Linux/2016-04/130070.htm

《Maven 实战》:Maven 实战教程 PDF http://www.linuxidc.com/Linux/2014-12/110503.htm

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-05/131844.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计6346字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中