How to include custom library into maven local repository?--转

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

时间: 2024-10-13 02:02:35

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

发布library到Maven仓库

发布library到Maven仓库 在Android Studio中想要使用一些第三方类库的时候非常方便,只需要在build.gradle中加入一行代码就可以了: dependencies { compile 'com.google.code.gson:gson:2.3.1' } 刚从Eclipse转过来的时候感觉太方便了,也不用下jar包然后拷贝到libs目录了,重要的是以后升级起来灰常方便,改个数字就好了. 那究竟它里面是怎么运转的呢?其实Android Studio是从Maven仓库中下载

将jar文件加到Maven的local repository中

对于Maven项目来说,日常使用的多数第三方java库文件都可以从Maven的Central Repository中自动下载,但是如果我们需要的jar文件不在Central Repository中,那么我们就需要手动将自己下载的jar文件加入到Maven的local reposotory中了,此时我们需要向Maven提供用于识别jar文件(可能多个)的groupId, artifactId和version等信息. 我并不打算讲怎么将一个下载的jar库加入到local repository中,我们

Maven依赖中类似was cached in the local repository样的错误

我们在使用maven编译一个项目时经常会遇到诸如此类的问题. Could not get the value for parameter encoding for plugin execution default-resources Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failure to find org.code

如何设置maven的local repository目录

step1:默认会放在~/.m2/repository目录下 (“~”代表用户的目录,比如windows下一般都是C:\Documents and Settings\[你的用户名]\.由于“Documents and Settings”中含有“空格”会导致“Illegal character in path”异常) 安装Maven后我们会在用户目录下发现.m2 文件夹.默认情况下,该文件夹下放置了Maven本地仓库.m2/repository.所有的Maven构件(artifact)都被存储到该

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/ maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Origi

Maven 迁移local repository

1.1 Maven仓库主要有2种: remote repository:相当于公共的仓库,大家都能访问到,一般可以用URL的形式访问 local repository:存放在本地磁盘的一个文件夹,例如,windows上默认是C:\Users\{用户名}\.m2\repository目录 1.2 Remote Repository主要有3种: 中央仓库:http://repo1.maven.org/maven2/ 私服:内网自建的maven repository,其URL是一个内部网址 其他公共仓

MAVEN奇葩问题was cached in the local repository, resolution will not be reattempted until

[ERROR] Non-resolvable import POM: Failure to find org.springframework.cloud:spring-cloud-dependencies:pom:Finchley.M7 in https://maven.aliyun.com/repository/public was cached in the local repository, resolution will not be reattempted until the upda

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.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are fo

maven build失败 (Failure to find io.renren:renren-security:pom:3.2.0 in http://maven.aliyun.com/nexus/content/groups/public/ was cached in the local repository...)

今天mvn clean package一个子工程(renren-admin)时报错: Failed to execute goal on project renren-admin: Could not resolve dependencies for project io.renren:renren-admin:war:3.2.0: Failed to collect dependencies at io.renren:renren-common:jar:3.2.0: Failed to rea