Nexus构建私服-学习笔记


目标:在本地构建Nexus私服

准备条件: jdk已安装, jdk环境变量已配置, maven已安装,eclipse

安装版本:https://www.sonatype.com/oss-thank-you-win64.zip


操作步骤:

1. 下载

进入https://www.sonatype.com/, 选择Product下载对应产品,我下载的是Nexus Repository OSS下面的nexus-3.2.0-01-win64.zip; 

2. 将nexus-3.2.0-01-win64.zip解压到目标文件夹,我解压到D:\bin\nexus-3.2.0-01-win64;

3. 打开CMD, 进入D:\bin\nexus-3.2.0-01-win64\nexus-3.2.0-01\bin, 运行命令 nexus.exe /install, 回车, 运行命令 nexus.exe /start, 回车, 

输入nexus.exe /status查看运行状况, 输出Running, 说明启动成功。如下图:



4. 访问Nexus服务器

打开浏览器, 访问http:localhost:8081/, 页面如下:



5. 登录

采用默认管理员账号登入, 账号admin, 密码admin123

6. 进入仓库

点击页面顶端的齿轮按钮,然后点击Repositories, 进入仓库, 如下图, 



7. 搜索

在订单搜索框Search components中输入junit, 发现没有任何结果。

因为目前还没有下载任何构建到本地仓库。

8. 在maven的settings.xml中设置引用该maven-central

创建文件夹D:\my-repos\.m2, 在该文件夹下创建文件夹repository, 拷贝maven安装目录下的 conf文件下面的settings.xml到D:\my-repos\.m2

下面, 修改settings.xml如下:

 需要修改:

localRepository, servers, mirrors (mirror的url就是maven-central仓库的url, 在仓库页面点击maven-central仓库列上面的copy按钮可以看到该链接, 复制过来就可以了)

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>D:\my-repos\.m2\repository</localRepository>
  <pluginGroups> 
  </pluginGroups>
  <proxies>   
  </proxies>
  <servers>
  	<server>
        <id>nexus</id>
        <username>admin</username>
        <password>admin123</password>
    </server>   
  </servers>  
  <mirrors>
  	<mirror>
        <id>nexus</id>
        <mirrorOf>*</mirrorOf>
        <url>http://localhost:8081/repository/maven-central/</url>
    </mirror>    
  </mirrors>  
  <profiles>
  	<profile>
            <id>center-repositories</id>
            <repositories>
            <repository>
                <id>central</id>
                <url>http://central</url>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>daily</updatePolicy>
                </snapshots>
            </repository>
            </repositories>
	    <pluginRepositories>
			<pluginRepository>
                <id>central</id>
                <url>http://central</url>
                <releases>
                    <enabled>true</enabled>
                    <updatePolicy>never</updatePolicy>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>daily</updatePolicy>
                </snapshots>
                </pluginRepository>
	    </pluginRepositories>
    </profile>    
  </profiles>  
  <activeProfiles>
        <activeProfile>center-repositories</activeProfile>
  </activeProfiles>  
</settings>

9. 在eclipse中构建项目的maven依赖

1. 进入eclipse的window>>preferences页面, 设置Maven选项下面的Installations, User Settings, 如下图:


10. 加载maven依赖

选中一个maven项目, 按组合键Alt + F5开始加载maven配置, 进入D:\my-repos\.m2\repository可以看到已经开始下载

11. 搜索

打开http://localhost:8081/, 搜索项目中pom.xml配置的构建,可以看到已经有搜索结果, 如下:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章