Maven私有仓库(Nexus)发布jar包

前言:maven管理项目,经常用到中央仓库没有的第三方jar包,需要将本地的jar包发布到私有库供项目使用。

1.使用之前需要修改本地maven的settings.xml配置文件,设置用户名密码

    <!-快照-->
   <server>
       <id>snapshots</id>
       <username>admin</username>
       <password>*</password>
    </server>
     <!-发布-->
    <server>
       <id>releases</id>
       <username>admin</username>
       <password>*</password>
    </server>
     <!-第三方-->   
       <server>
         <id>thirdparty</id>
         <username>admin</username>
         <password>*</password>
     </server>

2.发布maven项目,需要在pom.xml里配置

<distributionManagement>
    <repository>
        <id>releases</id>
        <url>http://ipaddress:8082/nexus/content/repositories/releases</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>Internal Snapshots</name>
        <url>http://ipaddress:8082/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>

3.再执行mvn命令

 mvn deploy -Dmaven.test.skip=true

4.发布第三方jar文件

mvn deploy:deploy-file -Dfile=/***.jar  -DgroupId=com.xxxx -DartifactId=wangnianTools -Dversion=1.0 -Dpackaging=jar -DrepositoryId=thirdparty -Durl=http://ipaddress:8082/nexus/content/repositories/thirdparty

5.使用maven私有库

<repository>
    <id>mynexus</id>
    <name>my internal repository</name>
    <url>http://ipaddress:8082/nexus/content/groups/public/</url>
</repository>

6.依赖发布的jar包

<dependency>
   <groupId>com.xxx</groupId>
   <artifactId>wangnianTools</artifactId>
   <version>1.0</version>
</dependency>

博客地址:http://my.oschina.net/wangnian

你可能感兴趣的:(maven,发布,jar包)