由于一些特殊原因需要把特定的jar文件发布到私有的maven库,方便发布和打包使用。下边给出简单的步骤和说明。
- 准备jar 文件, maven的配置文件和pom.xml
- maven的配置文件settings.xml 需要添加私库的用户信息
- <server>
 <username>{username}</username>
 <password>{password}</password>
 <id>{registryId}</id>
 </server>
 
- <server>
- pom.xml文件需要添加如下信息:
- groupid
- version
- artifactId
- name
- distributionManagement
- 示例如下:
- <?xml version=”1.0″?>
 <project
 xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”
 xmlns=”http://maven.apache.org/POM/4.0.0″
 xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.abc.xxx</groupId>
 <version>x.x.x</version>
 <artifactId>{artifactId}</artifactId>
 <name>{artifactId}</name><distributionManagement>
 <repository>
 <id>central</id>
 <name>artifactory-xxxxx-releases</name>
 <url>https://{私库地址}/artifactory/{maven artifactoryId}</url>
 </repository>
 <snapshotRepository>
 <id>snapshots</id>
 <name>artifactory-xxxxx-snapshots</name>
 <url>https://{私库地址}/artifactory/{maven artifactoryId}</url>
 </snapshotRepository>
 </distributionManagement></project>
 
- 复制jar文件和pom.xml到同一个目录,执行下边的命令
- mvn deploy:deploy-file -DgroupId={groupId} -DartifactId={DartifactId} -Dversion={version} -Dpackaging=jar -DrepositoryId={registryId 在settings.xml} -Dfile={jar文件} -DpomFile=pom.xml -Durl=https://{私库地址}/artifactory/{maven artifactoryId}
- pomFile是必须的,否则会自动创建一个文件,但是会导致jar无法使用
- url 和server的认证信息和ID要是正确的,路径也得正确
- 如果jar有其他的依赖,可以添加-Dclassifier=jar-with-dependencies
- 其他参数可以mvn –help查看
 

沟通交流合作请加微信!