原文地址: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 :

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

Demo.

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

<dependency>
<groupId>com.google.code</groupId>
<artifactId>kaptcha</artifactId>
<version>2.3</version>
</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. 【MFC】虚拟键代码

    一:首先介绍键盘消息 系统消息: ALT,F1,——F24等,是由系统内部处理的,程序本身就存在,比如F1是帮助键. WM_SYSKEYDOWN WM_SYSKEYUP WM_SYSCHAR 非系统消 ...

  2. C# 5.0新加特性

    1. 异步编程 在.Net 4.5中,通过async和await两个关键字,引入了一种新的基于任务的异步编程模型(TAP).在这种方式下,可以通过类似同步方式编写异步代码,极大简化了异步编程模型.如下 ...

  3. hiho1804 - 整数分解、组合数、乘法逆元

    题目链接 题目叙述很啰嗦,可以简化为:n个球[1-1e5],放到m个不同的桶里,一共多少种不同的放法.[桶里可以不放] ---------------------------------------- ...

  4. 洛谷P2894 [USACO08FEB]酒店Hotel_区间更新_区间查询

    Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ...

  5. FFmpeg avcodec_send_packet压缩包函数

    首先看一下FFmpeg关于该packet函数的注释: int avcodec_send_packet ( AVCodecContext *  avctx,     const AVPacket *  ...

  6. 漫谈 Google 的 Native Client(NaCl) 技术(二)---- 技术篇(兼谈 LLVM)

    转自:http://hzx5.blog.163.com/blog/static/40744388201172531637729/ 漫谈 Google 的 Native Client(NaCl) 技术( ...

  7. jquery.lazyload滚动不起作用

    昨天同事在开发图片懒加载功能时用到了lazyload,使用相当标准,然而结果却不如人意,在滚动时未能起作用.引用https://cdn.bootcss.com/jquery_lazyload/1.9. ...

  8. php多维数组的指定单个字段排序

    多维数组如何根据指定键值?比如现在有数组结构如下: ,,,,,'subject' => 'math'), 1 => array('name' => '3班','avgScore'=& ...

  9. 计蒜客 阿里天池的新任务—简单( KMP水 )

    链接:传送门 思路:KMP模板题,直接生成 S 串,然后匹配一下 P 串在 S 串出现的次数,注意处理嵌套的情况即可,嵌套的情况即 S = "aaaaaa" ,P = " ...

  10. nyoj92-图像有用区域【BFS】

    "ACKing"同学以前做一个图像处理的项目时,遇到了一个问题,他需要摘取出图片中某个黑色线圏成的区域以内的图片,现在请你来帮助他完成第一步,把黑色线圏外的区域全部变为黑色.    ...