maven添加本地jar包

本文转自:http://www.yiibai.com/maven/include-library-manully-into-maven-local-repository.html

这里有2个案例,需要手动发出Maven命令包括一个 jar 到 Maven 的本地资源库。

  1. 要使用的 jar 不存在于 Maven 的中心储存库中。
  2. 您创建了一个自定义的 jar ,而另一个 Maven 项目需要使用。



例如,kaptcha,它是一个流行的第三方Java库,它被用来生成 “验证码” 的图片,以阻止垃圾邮件,但它不在 Maven 的中央仓库中。

下载 “kaptcha”,将其解压缩并将 kaptcha-version.jar 复制到其他地方,比如:C盘。发出下面的命令:
C:\kaptcha-2.3.2.jar

mvn install:install-file -Dfile=c:\kaptcha-2.3.2.jar -DgroupId=com.google.code.kaptcha -DartifactId=kaptcha -Dversion=2.3.2 -Dpackaging=jar
显示信息:(第一次使用该命令会下载所需要插件和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-utils/3.0.5/plexus-utils-3.0.5.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.pom (3 KB at 0.3 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.pom (2 KB at 0.6 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.7/plexus-components-1.1.7.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-components/1.1.7/plexus-components-1.1.7.pom (5 KB at 2.2 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.8/plexus-1.0.8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/1.0.8/plexus-1.0.8.pom (8 KB at 3.9 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.pom (8 KB at 4.0 KB/sec)
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.jar
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.jar
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.jar (12 KB at 2.0 KB/sec)
Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.jar (226 KB at 10.9 KB/sec)
[INFO] Installing c:\kaptcha-2.3.2.jar to D:\repo_maven\.m2\repository\com\google\code\kaptcha\2.3.2\kaptcha-2.3.2.jar
[INFO] Installing C:\Users\dyb\AppData\Local\Temp\mvninstall945814896007531239.pom to D:\repo_maven\.m2\repository\com\google\code\kaptcha\2.3.2\kaptcha-2.3.2.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 37.472 s
[INFO] Finished at: 2016-09-08T23:16:06+08:00
[INFO] Final Memory: 8M/91M
[INFO] ------------------------------------------------------------------------
现在,“kaptcha” jar被复制到 Maven 本地存储库。

pom.xml中添加依赖就可以了

		<dependency>
			<groupId>com.google.code.kaptcha</groupId>
			<artifactId>kaptcha</artifactId>
			<version>2.3.2</version>
		</dependency>





  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值