Maven的是使用《三》之nexus私服的搭建

来源:互联网 发布:数控磨床编程代码 编辑:程序博客网 时间:2024/06/01 07:38

问题?Maven的是使用《三》之nexus私服的搭建

1.nexus私服是什么?

2.为什么要使用nexus私服?

3.它的作用是什么?

4.它的运行机制是什么?

5.它的运行流程是什么?

6.怎么搭建nexus私服?


1.nexus私服是什么?为什么要使用nexus私服?它的作用是什么?

前边简单介绍了Maven,而Maven默认提供的中央仓库是在远程网络服务Appache提供的,有时候我们所有、需要的jar包,还需要通过Apache在线下载,因为是外网,速度极度慢啊(反正小编是受不了),而且这对于我们开发造成效率低下的问题。

nexus私服就相当于在我们本地的局域网搭建了一个类似中央仓库的服务器,我们开始将中央仓库的一些资料下载到私服务器上,然后平时我们的maven项目就是直接访问局域网内的私服即可,有的就直接在本地仓库取出来即可,如果没有它会自动在网上下载到本地仓库。既节省了网络带宽也会加速项目搭建的进程,这样对我们开发来说,对公司来说都是非常好的选择。

2.它的运行机制是什么?

                   


3.它的运行流程是什么?

       我们搭建的nexus私服的仓库和仓库组:

(1)宿主仓库:也就是本地仓库,我从网上下载的插件就放在这里(../.m2/responty/)

(2)代理仓库:这个是网上资源仓库,本地没有的话就会在网上下载到本地仓库中.

(3)仓库组:代理服务有,中央服务器(可知的有Apache官网,还有中国的maven镜像网等等)

      

4.怎么搭建nexus私服?

(1)  下载nexus-webapp-1.9.2.4.war包,我这里用的是1.9.2.4版本的,也可以去官网(http://www.sonatype.com/download-oss-sonatype)下载,也可以点击这里


(2)将整个war包拷贝到tomcat下的webapps目录中,并启动服务,在地址栏输入:http://localhost:8080/nexus/就会出现以下画面了。

              

(3)点击右上角“log in”,输入username:admin 和Password:admin123登录,---->登陆成功

(4)点击Views/Repositories 中Repositories

(5)这里对Nexus内置仓库说明:
1)Maven Central:该仓库代理Maven中央仓库,其策略为Release,因此只会下载和缓存中央仓库中的发布版本构件。
2)Releases:这是一种策略为Release的宿主类型仓库,用来部署组织内部的发布版本构件。
3)Snapshots:这是一个策略为Snapshot的宿主类型仓库,用来部署组织内部的快照版本构件。
4)3rd party:这是一个策略为Release的宿主类型仓库,用来部署无法从公共仓库获得的第三方发布版本构件。
5)Public Repositories:该仓库组将上述所有策略为Release的仓库聚合并通过一致的地址提供服务。


(6)创建宿主目录和代理仓库(我配置的时候没做这一步,因为在我maven deploy这个命令的同时,会将其一起部署到这上面来)


Hosted:本地仓库,通常我们会部署自己的构件到这一类型的仓库。 
包括3rd party仓库,Releases仓库,Snapshots仓库
Proxy:代理仓库,它们被用来代理远程的公共仓库,如maven中央仓库。 
Group:仓库组,用来合并多个hosted/proxy仓库,通常我们配置maven依赖仓库组。 


点击Public Repositories仓库,在Configurations栏中选取需要合并的仓库,点击箭头加到左边保存即可
下载Index索引并进行构建搜索(GAV搜索)

(7)***配置所有构件均从私服下载,在~/.m2/setting.xml中配置如下(这一步很关键,说明了为什么要搭建nexus私服的原因):

     进入setting.xml中进去替代相应的内容即可:

  <!-- servers   | This is a list of authentication profiles, keyed by the server-id used within the system.   | Authentication profiles can be used whenever maven must make a connection to a remote server.   |-->   <!-- Nexus的访问权限控制,这就是最开始进入http://localhost:8080/nexus/进入的页面登陆所用的用户设置处 --> <servers><server><id>releases</id><username>admin</username><password>admin123</password></server><server><id>snapshots</id><username>admin</username><password>admin123</password></server></servers>

<!-- mirrors   | This is a list of mirrors to be used in downloading artifacts from remote repositories.   |    | It works like this: a POM may declare a repository to use in resolving certain artifacts.   | However, this repository may have problems with heavy traffic at times, so people have mirrored   | it to several places.   |   | That repository definition will have a unique id, so we can create a mirror reference for that   | repository, to be used as an alternate download site. The mirror site will be the preferred    | server for that repository.   |--><mirrors> <mirror> <!--此处配置所有的构建均从私有仓库中下载 *代表所有,也可以写central --> <id>nexus</id><!-- 这里的id是nexus私服包的名字,也就是拷入tomcate下的那个war包 --> <mirrorOf>*</mirrorOf> <url>http://192.168.1.100:8080/nexus/content/groups/public</url> <!-- 这里的是端口号要和你tomcate里那个server文件设置的端口号一样,其他的保持默认 --> </mirror> </mirrors>

<!-- profiles   | This is a list of profiles which can be activated in a variety of ways, and which can modify   | the build process. Profiles provided in the settings.xml are intended to provide local machine-   | specific paths and repository locations which allow the build to work in the local environment.   |   | For example, if you have an integration testing plugin - like cactus - that needs to know where   | your Tomcat instance is installed, you can provide a variable here such that the variable is    | dereferenced during the build process to configure the cactus plugin.   |   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles   | section of this document (settings.xml) - will be discussed later. Another way essentially   | relies on the detection of a system property, either matching a particular value for the property,   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a    | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.   | Finally, the list of active profiles can be specified directly from the command line.   |   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact   |       repositories, plugin repositories, and free-form properties to be used as configuration   |       variables for plugins in the POM.   |   |--><profiles> <profile> <id>nexus</id><!-- 这里的id是nexus私服包的名字,也就是拷入tomcate下的那个war包 --> <!--所有请求均通过镜像,这个profiles指明镜像地址 --> <repositories> <repository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://central</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile></profiles>

<!-- activeProfiles   | List of profiles that are active for all builds.   |   --><activeProfiles> <!--make the profile active all the time --> <activeProfile>nexus</activeProfile><!-- 这里的activeProfile是nexus私服包的名字,也就是拷入tomcate下的那个war包 --></activeProfiles>


一共就这四个改动之处,改好了,我们的本地仓库setting.xml文件也就改好了。

(8)部署构建到Nexus,包含Release和Snapshot, 在项目根目录中pom.xml中配置

这个配置的作用在哪里呢?把项目发布到本地nexus私服上,别人想用这个项目,也可以直接下载使用。

<distributionManagement> <repository>     <id>releases</id>     <name>Internal Releases</name>     <url>http://localhost:8010/nexus/content/repositories/releases/</url> </repository> <snapshotRepository>     <id>snapshots</id>     <name>Internal Snapshots</name>     <url>http://localhost:8010/nexus/content/repositories/snapshots/</url> </snapshotRepository>   </distributionManagement>



0 0