转:建立maven私服

一、下载安装与配置

下载

到官网下载:https://www.sonatype.com/download-oss-sonatype

 
image.png

下载的是oss3.x版本的(当时最新版),


 
image.png

安装

1、先将下载后的zip文件解压到指定文件夹
2、直接双击exe文件会闪退,所以使用命令行,管理员方式运行cmd

 
image.png

安装:nexus.exe /install
卸载:nexus.exe /uninstall
启动:nexus.exe /start
停止:neuxs.exe /stop
3、(可做可不做)为了方便使用将bin弄成系统环境变量
4、安装并启动完成后 直接访问http://localhost:8081/(是默认端口) 默认用户:admin 密码:admin123
5、如果要修改端口,就修改配置文件中的 nexus-3.14.0-04etc exus-default.properties 的 application-port
## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
nexus-context-path=/

# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=
 nexus-pro-feature

配置用户

1、自改密码,进入用户账户,change password-->修改为其他密码就行了(1QsAZD0SV)
2、有其他问题直接上官网看文档


二、使用方式

上传jar包(三种方式)

1、如果是使用界面的update比较简单
2、使用配置方式 在maven的setting.xml文件中配置,要分清是自己下载的maven或者是idea的maven

<!-- 把jar包发布到私服中 -->
 <!--   配置服务器--><server> 
    <id>maven-public</id> 
    <username>admin</username> 
    <password>1QsAZD0SV</password> </server> <server> 
    <id>maven-releases</id> 
    <username>admin</username> 
    <password>1QsAZD0SV</password> </server> <server> 
    <id>maven-snapshots</id> 
    <username>admin</username> 
    <password>1QsAZD0SV</password> </server> 

项目的pom文件

<distributionManagement>
        <repository>
            <id>maven-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://localhost:8081/repository/maven-releases/</url>
        </repository>
        <snapshotRepository>
            <id>maven-snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://localhost:8081/repository/maven-snapshots/</url>
        </snapshotRepository>
</distributionManagement>

点击idea中deploy命令即可成功 mvn clean deploy 2.1.3 也可以使用命令行将下载的jar发布到私服

mvn deploy:deploy-file -DgroupId=com.weepal.wp-common 
-DartifactId=wp-common -Dversion=1.3.0 -Dpackaging=jar 
-DrepositoryId=nexus -Dfile=E:Documentwp-common-1.3.0-RELEASE.jar-Durl=http://localhost:8081/repository/maven-release/

com.weepal.wp-common为pom中的groupId中的内容;
wp-common为pom中的artifactId中的内容;
1.3.0为pom中的version中的内容; 同时在maven中要添加权限

<server>
      <id>nexus</id>
      <username>admin</username>
      <password>1QsAZD0SV</password>
     </server>
 <repository>
    <id>nexus</id>
    <url>http://localhost:8081/repository/maven-release/</url>
    <releases>
     <enabled>true</enabled>
    </releases>
    <snapshots>
     <enabled>true</enabled>
    </snapshots>
 </repository>

从私服下载jar包

1、在pom文件中配置

<!-- 假如没有私服 ,则 本地仓库找不到,则访问中心仓库
     假如有私服 :访问顺序
       首先访问本地仓库
   本地仓库没有,则访问私服仓库
   私服仓库也没有,则访问中心仓库
 -->
     <!--下载jar配置开始-->
    <repositories>
        <repository>
            <id>alimaven</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/libs-milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>nexus</id>
            <name>Nexus Repository</name>
            <url>http://localhoot:8081/repository/maven-public/</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>Nexus Plugin Repository</name>
            <url>http://localhoot:8081/repository/maven-public/</url>
        </pluginRepository>
    </pluginRepositories>
    <!--下载jar包配置结束-->


作者:nayli
链接:https://www.jianshu.com/p/93fac0ac2202
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
原文地址:https://www.cnblogs.com/059212315/p/12100282.html