原文地址:https://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/

There are 2 cases that you need to issue Maven’s command to include a jar into the Maven local repository manually.

  1. The jar you want to use doesn’t exist in the Maven center repository.
  2. You created a custom jar, and need to use for another Maven project.

P.S Trust me, there are still many jars that doesn’t support Maven.

Case study

For example, kaptcha, a popular third party Java library, which is used to generate “captcha” image to stop spam, but it’s not available in the Maven center repository.

In this tutorial, we will show you how to install the “kaptcha” jar into your Maven’s local repository.

1. mvn install

Download the “kaptcha“, extract it and copy the kaptcha-version.jar to somewhere else, for example, c drive. Issue following command :

  1. mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code
  2. -DartifactId=kaptcha -Dversion={version} -Dpackaging=jar

Demo.

  1. D:\>mvn install:install-file -Dfile=c:\kaptcha-2.3.jar -DgroupId=com.google.code
  2. -DartifactId=kaptcha -Dversion=2.3 -Dpackaging=jar
  3. [INFO] Scanning for projects...
  4. [INFO] Searching repository for plugin with prefix: 'install'.
  5. [INFO] ------------------------------------------------------------------------
  6. [INFO] Building Maven Default Project
  7. [INFO] task-segment: [install:install-file] (aggregator-style)
  8. [INFO] ------------------------------------------------------------------------
  9. [INFO] [install:install-file]
  10. [INFO] Installing c:\kaptcha-2.3.jar to
  11. D:\maven_repo\com\google\code\kaptcha\2.3\kaptcha-2.3.jar
  12. [INFO] ------------------------------------------------------------------------
  13. [INFO] BUILD SUCCESSFUL
  14. [INFO] ------------------------------------------------------------------------
  15. [INFO] Total time: < 1 second
  16. [INFO] Finished at: Tue May 12 13:41:42 SGT 2009
  17. [INFO] Final Memory: 3M/6M
  18. [INFO] ------------------------------------------------------------------------

Now, the "kaptcha" jar is copied to your Maven local repository.

2. pom.xml

After installed, just declares the kaptcha coordinate in pom.xml.

  1. <dependency>
  2. <groupId>com.google.code</groupId>
  3. <artifactId>kaptcha</artifactId>
  4. <version>2.3</version>
  5. </dependency>

3. Done

Build it, now the "kaptcha" jar is able to retrieve from your Maven local repository.

How to include custom library into maven local repository?--转的更多相关文章

  1. 【转】Install Oracle Jdbc driver in your Maven local repository

    Install Oracle Jdbc driver in your Maven local repository If you are using Oracle, you must first in ...

  2. Maven 迁移local repository

    1.1 Maven仓库主要有2种: remote repository:相当于公共的仓库,大家都能访问到,一般可以用URL的形式访问,一般默认的地址:http://search.maven.org/ ...

  3. maven编译项目时提示:cached in the local repository

    今天使用命令mvn compile编译maven项目时提示错误信息,部分错误信息如下: ...... was cached in the local repository, resolution wi ...

  4. Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from http://repo.maven.apache.org/ maven2 was cached in the local repository, resolution will not be reattempted until the update interv

    Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from http://repo.maven.apache.org/  mave ...

  5. Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval o

    pom.xml报错: Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from https://repo.maven.apach ...

  6. 将jar文件加到Maven的local repository中

    对于Maven项目来说,日常使用的多数第三方java库文件都可以从Maven的Central Repository中自动下载,但是如果我们需要的jar文件不在Central Repository中,那 ...

  7. Failure to transfer org.springframework.boot:spring-boot-starter-parent:pom:2.0.1.RELEASE from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempt

    第一次用 Spring Starter Project 创建一个Spring应用时,POM 文件报错: Project build error: Non-resolvable parent POM f ...

  8. 如何设置maven的local repository目录

    step1:默认会放在~/.m2/repository目录下 (“~”代表用户的目录,比如windows下一般都是C:\Documents and Settings\[你的用户名]\.由于“Docum ...

  9. [Perl]Can't link/include C library 'ft2build.h', 'freetype', aborting.

    原文:http://www.code-by.org/viewtopic.php?f=60&t=284 错误提示 Font-FreeType-0.07>perl Makefile.PL B ...

随机推荐

  1. c++中的while(cin)问题

    xp系统中利用dev-cpp进行编程,语句while(cin>>str),str是个string类型,在一行中输入几个string,末位加个ctrl+z,输入没有结束,除非出入换行后,再输 ...

  2. DELPHI调试出现disconnected session的解决办法

    我在控制面板中,是禁用了UAC的,如下图 但是,在注册表中启用了UAC(EnableLUA), 工程中请求了管理员权限,如下图: 所以,整个权限请求混乱了. 解决办法,要么把注册表的LUA设置为0,要 ...

  3. Kafka学习笔记(5)----Kafka的Consumer

    1. Pull vs Push Producer主动的通过push将消息发布到Broker上,Consumer通过Pull的的方式从Broker消息消息. 通过Push的方式由于是一有消息就推到Bro ...

  4. WPF 利用RichTextBox 打印出不同颜色的文本

    using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows ...

  5. day03深浅拷贝、文件操作和函数初识

    一.赋值.浅拷贝与深拷贝 直接赋值:其实就是对象的引用(别名). 浅拷贝(copy):拷贝父对象,不会拷贝对象的内部的子对象. 深拷贝(deepcopy): copy 模块的 deepcopy 方法, ...

  6. Nginx配置udp/tcp代理

    #编译 ./configure --prefix=/servyouapp/nginx --with-stream --with-http_stub_status_module #nginx.conf部 ...

  7. 两个sed小技巧:sed "/变量/变量/"

    两个sed小技巧 在写shell时使用sed处理一些输出,遇到两个问题,在网上找到了相应的解决办法,在此处备份一下. [ sed处理空字符 ] 空字符,它的ASCII码值为0.在sed中如何标识空字符 ...

  8. 原生js模拟双色球

    <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...

  9. webstorm + babel

    网上有很多关于如何设置babel的.我学习着设置,但总差那么几步,没能满足我的需求. 我使用的是webStorm2017.1版本. babel安装准备 使用webStorm自带的filewatcher ...

  10. Project Euler 34 Digit factorials

    题意:判断一个数 N 的各个位数阶乘之和是否为其本身,找出所有符合要求的数然后求和 思路:此题思路跟 30 题相同,找到枚举上界 10 ^ n <= 9! × n ,符合要求的 n < 6 ...