maven开发常用总结

tech2026-04-01  0

一、maven强制更新

本地仓库上可能缺少某个版本的jar包,可以使用命令更新maven的仓库

mvn clean install -e -U -e详细异常,-U强制更新

二、 如果把某个jar包放到maven仓库?

本地开发或者主机上构建部署项目有时会缺少某个jar包,如果公司私服/中央仓库(由于网络原因等)下载不了,就需要我们手动上传到本地仓库。

这里以hutool工具包为例。从mvnrepository下载到本地,在已知GAV的情况下

<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all --> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.4.5</version> </dependency>

执行命令:

mvn install:install-file -Dfile=F:\softwareInstall\repo\cn\hutool\hutool-all\4.6.4\hutool-all-4.6.4.jar -DgroupId=cn.hutool -DartifactId=hutool-all -Dversion=4.6.4 -Dpackaging=jar

-Dfile :jar包的存在位置。

三、如何上传jar包到公司私服/远程仓库?

比如说步骤二中的4.6.4版本的jar包公司私服上不存在,我们可以手动传到私服nexus。

3.1方式一:通过nexus的登陆页面。

通过页面,需要一个有权限的账号密码,登陆进去选择相应的仓库,

3.2方式二:通过命令

mvn deploy:deploy-file -DgroupId=cn.hutool -DartifactId=hutool-all -Dversion=4.6.4 -Dpackaging=jar -Dfile=F:\softwareInstall\repo\cn\hutool\hutool-all\4.6.4\hutool-all-4.6.4.jar -Durl=http://test.upload.com.cn/nexus/content/repositories/CRM_CMI_Release -DrepositoryId=CRM_OUP_Releasepause

3.3 通过IDEA Maven的deploy

这种方式常用来把快照(Snapshot)版本的jar包添加到私服上(也可以打release版本)。

首先在pom文件添加仓库地址 <!-- 仓库仓库地址 --> <distributionManagement> <repository> <id>youJarName-release</id> <url>http://test.upload.com.cn/nexus/CRM_OUP_Release/</url> </repository> <snapshotRepository> <id>youJarName-snapshot</id> <url>http://test.upload.com.cn/nexus/CRM_OUP_Snapshot/</url> </snapshotRepository> </distributionManagement> 然后再settings.xml中添加仓库的用户名密码 <server> <id>youJarName-snapshot</id> <username>admin</username> <password>pwd</password> </server> <server> <id>youJarName-release</id> <username>admin</username> <password>pwd</password> </server> <pluginRepositories> <pluginRepository> <id>CRM_OUP_Snapshot</id> <name>nexus</name> <url>http://test.upload.com.cn/nexus/CRM_OUP_Snapshot</url> <snapshots><enabled>true</enabled></snapshots> <releases><enabled>true</enabled></releases> </pluginRepository> <pluginRepository> <id>CRM_OUP_release</id> <name>nexus</name> <url>http://test.upload.com.cn/nexus/CRM_OUP_release</url> <snapshots><enabled>true</enabled></snapshots> <releases><enabled>true</enabled></releases> </pluginRepository> </pluginRepositories>

 

最后idea中选中项目--maven--plugins--deploy。

最新回复(0)