一、下载完Nexus以后进入目录\Nexus\nexus-2.12.1-01\bin\jsw\这目录底下有各类各样的操做系统的子目录,根据系统进入到对应目录中,个人是64位windows看到的内容以下:
web
console-nexus.bat是控制台启动nexus,用这个能够启动和重启。apache
install-nexus.bat先将nexus注册成windows服务,之后直接启动了。相应的uninstall-nexus是卸载服务windows
start-nexus.bat和stop-nexus.bat分别是启动和关闭服务。安全
二、登陆Nexus提供的管理后台,由于我们下载的目录里有自带的容器了,因此能够直接本机地址:游览器中输入http://localhost:8081/nexus/,出现以下图所示就表明nexus已经启动成功。默认端口是8081,能够在\Nexus\nexus-2.12.1-01\conf\nexus.properties这个文件里更改端口app
# Jetty sectionwebapp
application-port=端口号maven
application-host=0.0.0.0测试
nexus-webapp=${bundleBasedir}/nexusui
nexus-webapp-context-path=/nexusurl
能够点右上角的log in 登陆默认的用户名和密码:admin/admin123。嘿嘿好多公司的私服都是默认的用户名和密码,之前没搭过私服,在之前公司本身maven的settings.xml里见到这用户名和密码还颇感意外,如今明白了。
三、登陆后点Repositories以后右侧列表入下:有几个概念本身以前老是不明白,借机会查了一下表示的意思。
最经常使用的实际就是这三个了。
Releases: 用来部署管理内部的发布版本构件的宿主类型仓库
Snapshots:用来部署管理内部的快照版本构件的宿主类型仓库
Central: 用来代理maven中央仓库中发布版本构件的仓库
这几个知道一下就好了。
3rd party: 没法从公共仓库得到的第三方发布版本的构件仓库
Apache Snapshots: 用了代理ApacheMaven仓库快照版本的构件仓库
Central M1 shadow: 用于提供中央仓库中M1格式的发布版本的构件镜像仓库
Codehaus Snapshots: 用来代理CodehausMaven 仓库的快照版本构件的仓库
重点讲一下PublicRepositories
PublicRepositories:这个对应的Type是group,是默认的仓库组(settings.xml里最经常使用的配置这个),这个概念maven里没有的,maven就只管凭坐标取包。点中这一行后在下面的几个标签里选configuration往下面拖一下有Order Group Repositories:它就是说将几个仓库放一块儿管理,好比公司里可能有本身封装的一系列jar包独立建一个仓库名字,把它们和默认的这几个仓库一块儿管理,取包的时候按照这里的顺序,通常把central放最后由于这个是中央仓库,从apache的中央仓库取最慢。
四、接下来最重要的是配置Nexus和开启索引,若是咱们不开启这个,在里面搜索的时候啥也找不到,开启之后搜索就能够找到坐标了。搜索的时候能够按照:
Keyword Search 关键字搜索
Classname Search 类名
GAV Search 没查到猜的(g对应group,v对应version,a对应artifactid,说白了就是坐标)
Checksum Search 校验和搜索,没用过
下载远程索引到本地:仍是点中Central,Apache SpnapShots 在下面把Download Remote Indexes 属性改为True以后点save,在上面的Central,Apache SpnapShots上右键点Repair Index,就开启了,等着它下一下子索引目录。以后点Browse Index就能够看到目录结构了,此时搜索就能够用了。
五、接下来就是使用的问题了在maven的settings.xml文件里首先是配置本机使用的下载的jar包保存的路径,就是所谓的localRepository本地仓库问题。
<!-- localRepository | The path to the local repository maven will use to store artifacts. | | Default: ${user.home}/.m2/repository <localRepository>/path/to/local/repo</localRepository> --> <localRepository>E:/repository/maven_repository</localRepository>
而后是镜像,这里mirrorOf能够写central就是只为central作镜像,若是写*号则是表明全部仓库,settings.xml里配置的都是全局的就是针对全部使用这个maven的工程。
<mirror> <id>nexus</id> <mirrorOf>*</mirrorOf> <name>NexusMirror</name> <url>http://172.20.50.20:8081/nexus/content/groups/public/</url> </mirror>
<!-- interactiveMode | This will determine whether maven prompts you when it needs input. If set to false, | maven will use a sensible default value, perhaps based on some other setting, for | the parameter in question. | | Default: true <interactiveMode>true</interactiveMode> --> <!-- offline | Determines whether maven should attempt to connect to the network when executing a build. | This will have an effect on artifact downloads, artifact deployment, and others. | | Default: false <offline>false</offline> -->
interactiveMode
指定Maven是否试图与用户交互来获得输入,默认是true
usePluginRegistry
若是设置为true,则在{user.home}/.m2下须要有一个plugin-registry.xml来对plugin的版本进行管理。默认是false
offline
若是不想每次编译的时候都去查找远程中心仓库,就须要设置为true,但前提是本地仓库中已有须要的jar包,默认是false
Servers
通常私服弄好了就不须要这个了,可是若是有安全方面的须要,须要提供认证信息才能访问这些私服,这时就须要使用servers元素(须要注意的是配置私服的信息是在pom文件中,可是认证信息则是在setting.xml中,这是由于pom文件每每是被提交到代码仓库中供全部成员访问的,而setting.xml是存放在本地的,这样是安全的)。
Profile
这个须要详细说一下,pom.xml文件里也是能够配这个的,可是settings.xml是全局的,profile能够根据不一样的条件就是他的id来激活不一样的构建过程。它的原文注释里也很清楚的写了比较推荐的命名方式是env-test/env-product这种形式,通常能够用来区分生产环境和测试环境用不一样的构建。
<profile> <id>pahc-dev</id> <repositories> <repository> <id>local-nexus</id> <name>local private nexus</name> <url>http://172.20.50.20:8090/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> </profile>
激活不一样的构建有不少种,好比仍是在这个配置文件里用activeProfiles标签
<activeProfiles> <activeProfile>pahc-dev</activeProfile> </activeProfiles>
也能够用maven命令在打包的时候加命令 mvn package –P pahc-dev 若是是 mvn package -P !pahc-dev 就是不启用这个构建。还能够根据操做系统来启动某个构建,或者根据文件路径,或者根据jdk来启用某个构建。
来一个jdk的例子
<profiles> <profile> <id>profileTest1</id> <jdk>[1.4,1.7)</jdk> </profile> <profiles>
参考了两个博客:
http://blog.csdn.net/liujiahan629629/article/details/39272321
http://blog.csdn.net/stypace/article/details/38458377