使用Nexus配置Maven私有仓库

    • 下载并且安装nexus
    • 调整setting.xml的配置
    • 测试上传jar包到私服服务器

下载并且安装nexus

1.从以下网址【https://www.sonatype.com/oss-thank-you-tar.gz】下载对应的版本,我下载的是linux版本的。**

解决到安装目录,我安装的是 /usr/local ;解压命令: tar -zxf nexus-3.12.1-01-unix.tar.gz
注意要先安装JDK8,nexus3.x支持的jdk版本最低是1.8.
检查下jdk的安装版本:

[root@www ~]# java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode)
[root@www ~]# 

2.进入到bin目录,执行./nexus run &,出现如下界面启动成功,启动时需要一定的时间。

2018-07-20 03:20:20,689+0800 INFO  [jetty-main-1] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - 
-------------------------------------------------

Started Sonatype Nexus OSS 3.12.1-01

-------------------------------------------------
2018-07-20 03:20:22,350+0800 INFO  [qtp28871576-45] *UNKNOWN org.apache.shiro.session.mgt.AbstractValidatingSessionManager - Enabling session validation scheduler...
2018-07-20 03:20:22,396+0800 INFO  [qtp28871576-45] *UNKNOWN org.sonatype.nexus.internal.security.anonymous.AnonymousManagerImpl - Using default configuration: AnonymousConfiguration{enabled=true, userId='anonymous', realmName='NexusAuthorizingRealm'}
2018-07-20 03:20:23,152+0800 INFO  [qtp28871576-171] *UNKNOWN com.sonatype.nexus.analytics.internal.EventSubmitterImpl - Service URL: https://analytics.sonatype.com

3.访问http://192.168.0.50:8081/ 可以登录

使用Nexus配置Maven私有仓库_第1张图片

默认端口号:8081
默认账号:admin
默认密码:admin123

4.修改配置

4.1、修改运行nexus3所使用的用户:
   [root@www bin]# vi nexus.rc
   run_as_user=”root”
4.2、修改nexus3启动所使用的jdk版本
   [root@www bin]#vi nexus
          INSTALL4J_JAVA_HOME_OVERRIDE=/usr/program/software/java8
4.3、修改nexus3默认端口
    [root@www bin]# vi nexus-default.properties
           application-port=8282
4.4、修改nexus3数据以及相关日志的存储位置
           [root@www bin]# vi nexus.vmoptions 
    -XX:LogFile=./sonatype-work/nexus3/log/jvm.log
    -Dkaraf.data=./sonatype-work/nexus3
    -Djava.io.tmpdir=./sonatype-work/nexus3/tmp

调整setting.xml的配置

1.配置server
  <servers>
    <server>    
      <id>nexus-releasesid>    
      <username>adminusername>    
      <password>admin123password>    
    server>    
    <server>    
      <id>nexus-snapshotsid>    
      <username>adminusername>    
      <password>admin123password>    
    server> 
 servers>

2.配置mirror
        <mirror>     
            <id>nexus-releasesid>     
            <mirrorOf>*mirrorOf>     
            <url>http://192.168.0.50:8081/repository/maven-public/url>     
        mirror>    
        <mirror>     
            <id>nexus-snapshotsid>     
            <mirrorOf>*mirrorOf>     
            <url>http://192.168.0.50:8081/repository/maven-snapshots/url>     
        mirror>


   
        <mirror>
            <id>alimavenid>
            <name>aliyun mavenname>
            <url>http://maven.aliyun.com/nexus/content/groups/public/url>
            <mirrorOf>centralmirrorOf>
        mirror>

3.配置profile:
    <profile>    
      <id>nexusid>    
      <repositories>    
        <repository>    
          <id>nexus-releasesid>    
          <url>http://nexus-releasesurl>    
          <releases><enabled>trueenabled>releases>    
          <snapshots><enabled>trueenabled>snapshots>    
        repository>    
        <repository>    
          <id>nexus-snapshotsid>    
          <url>http://nexus-snapshotsurl>    
          <releases><enabled>trueenabled>releases>    
          <snapshots><enabled>trueenabled>snapshots>    
        repository>    
      repositories>    
      <pluginRepositories>    
         <pluginRepository>    
                <id>nexus-releasesid>    
                 <url>http://nexus-releasesurl>    
                 <releases><enabled>trueenabled>releases>    
                 <snapshots><enabled>trueenabled>snapshots>    
               pluginRepository>    
               <pluginRepository>    
                 <id>nexus-snapshotsid>    
                  <url>http://nexus-snapshotsurl>    
                <releases><enabled>trueenabled>releases>    
                 <snapshots><enabled>trueenabled>snapshots>    
             pluginRepository>    
         pluginRepositories>    
    profile>  

4.使用profile

     <activeProfiles>    
      <activeProfile>nexusactiveProfile>    
    activeProfiles>

测试上传jar包到私服服务器

  • 在父pom中配置私服服务器地址
     <distributionManagement>
        <repository>
            <id>nexus-releasesid>
            <url>
               http://192.168.0.50:8081/repository/maven-public/
            url>
        repository>
        <snapshotRepository>
            <id>nexus-snapshotsid>
            <url>
                http://192.168.0.50:8081/repository/maven-snapshots/
            url>
        snapshotRepository>
    distributionManagement>
  • 开始上传jar包
    使用Nexus配置Maven私有仓库_第2张图片

注:其他如果是其他用户的话, 没有部署的权限;需要对应的授权,部署授权的步骤如下:

使用Nexus配置Maven私有仓库_第3张图片
使用Nexus配置Maven私有仓库_第4张图片

你可能感兴趣的:(常用技术)