怎么实现将本地jar添加到Maven仓库

发布时间:2022-08-31 10:03:29 作者:iii
来源:亿速云 阅读:180

本篇内容介绍了“怎么实现将本地jar添加到Maven仓库”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

手动将本地jar添加到Maven仓库

将jar添加到本地仓库的做法

以下面pom.xml依赖的jar包为例:

实际项目中pom.xml依赖写法:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>3.1.0.RELEASE</version>
</dependency>

Maven 安装 JAR 包的命令是:

mvn install:install-file 
-Dfile=jar包的位置 
-DgroupId=上面的groupId 
-DartifactId=上面的artifactId 
-Dversion=上面的version 
-Dpackaging=jar

例如我的这个spring-context-support-3.1.0.RELEASE.jar 文件放在了"D:\mvn\"中

则命令为:

mvn install:install-file 
-Dfile=D:\mvn\spring-context-support-3.1.0.RELEASE.jar 

-DgroupId=org.springframework 

-DartifactId=spring-context-support 

-Dversion=3.1.0.RELEASE 

-Dpackaging=jar

注意:任何路径和名称不要有中文和空格,以防出现莫名其妙的错误。

还可以解决本地仓库是从别人那边复制的,但是需要的jar包中央仓库不存在,导致的执行package时出现以下异常

Failed to execute goal on project relayserver: Could not resolve dependencies for project com.xxx:xxx:war:1.0-SNAPSHOT: Failure to find xxx.xxx:xxx:jar:1.0 in http://maven.aliyun
.com/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of nexus-aliyun has elapsed or updates are forced 

不讲jar包添加到本地仓库也可在maven工程中使用外部jar包做法

假设将包htmlparser.jar放入了项目下的lib目录中 :

-> ${project}/lib/htmlparser.jar

则pom.xml文件中依赖可以如下:

<dependency>
    <groupId>com.htmlparser</groupId>
    <artifactId>htmlparser</artifactId>
    <version>2.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/htmlparser.jar</systemPath>
</dependency>

手动向maven仓库添加jar包的cmd命令

手动向maven库里面添加jar包,要以管理员身份进行添加,在jar包目录打开cmd

mvn install:install-file -Dfile=文件绝对路径 -DgroupId=maven仓库下面的路径 -DartifactId=jar包名-Dversion=jar包版本 -Dpackaging=jar -DgeneratePom=true

例如:

mvn install:install-file -Dfile=E:/quartz-2.2.1.jar -DgroupId=org.quartz-scheduler -DartifactId=quertz -Dversion=2.2.1 -Dpackaging=jar -DgeneratePom=true

“怎么实现将本地jar添加到Maven仓库”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. Maven安装本地jar到本地仓库
  2. Maven 添加本地jar文件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

jar maven

上一篇:如何使用Go http重试请求

下一篇:java Date和SimpleDateFormat时间类怎么用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》