MAVEN指南-七、使用Nexus建立maven私有仓库

一、为何须要maven私有仓库?java

从Maven中央仓库下载所需的jar包,须要外网的支持。若是公司不能上外网的话则不能从中央仓库下载所需jar包,公司网速慢的时候也会影响项目构建的速度。用户能够用nexus建立私有的maven仓库。

 

二、下载和部署Nexusgit

首先下载nexus,下载地址是http://www.sonatype.org/nexus/go
在此页面能够下载最新版本的Nexus,能够下载zip包也能够下载war包。须要注意的是两种包的部署方式不同。

 

zip包部署方式github

复制代码

a.把zip包解压到指定路径如“D:\workbase”

b.运行cmd而后进入“D:\workbase\nexus-2.6.0-05\bin”路径

c.而后运行nexus.bat install命令安装nexus

d.而后运行nexus.bat start命令启动nexus

复制代码

其余命令有nexus.bat stop中止 nexus.bat restart重启 nexus.bat uninstall卸载web

 

war包部署方式apache

直接把war包放到tomcat的webapp下,启动tomcat便可。bootstrap

在浏览器地址栏输入http://localhost:8088/nexus/即进入nexus首页。有管理nexus要以管理员身份登陆,点击首页右上角的login输入默认登陆名、密码admin/admin123便可登陆。浏览器

注意与jdk的版本搭配tomcat

官方下载的最新版本是2.6.0-05,jdk1.6版本启动nexus有错误不能启动,错误以下:服务器

Launching a JVM...
jvm 5    | java.lang.UnsupportedClassVersionError: org/sonatype/nexus/bootstrap/jsw/JswLauncher : Unsupported major.minor version 51.0app

在官网下载早期版本的Nexus如2.4.0替换掉便可。

登陆系统后点击左侧菜单栏Views/Repositories下的Repositories选择Central仓库点击下边的Configuration把Download Remote Indexes属性设为True保存便可。

 

点击Repositories ,能够看到仓库列表,包括下面几种:

Public Repositories      仓库组 
3rd part                     三方库,能够上传jar包到这个仓库
Central                      maven中心仓库
Releases                    本身项目中发布的构建 
Snapshots                 trunk 下开发一个项目

而后在Central仓库上右键而后点击Repair Index 便可下载中心仓库的索引文件,稍等几分钟点击下边的Browse Index便可看见下载的索引文件。

往Public Repositories中添加Central仓库,点击Public Repositories在Configuration选项卡中把Central移到左侧便可。

 

最后在本身的应用中把中心仓库配置成创建的私有仓库地址便可,修改本地的maven配置文件,C:\Documents and Settings\用户名\.m2\setting.xml

在mirrors添加mirror节点地址指向创建的私有仓库地址,mirrorOf属性值设为central为了覆盖超级pom中指定的central地址,以下

 

 

 

Maven 仓库

Maven 包集中存放的地方,就是 Maven 仓库。这些仓库,能够是放在本地,也能够放在某个远程服务器上。 能够是私有仓库,也能够是公开的。

  • 存在本地的
maven {
 url 'file:///Users/my-user-name/Documents/Android/repo/'
}
  • 存在内网服务器的
maven {
 url 'http://192.168.99.100:8081/content/repositories/releases/'
}
  • 存在某个远程服务器的
maven {
    url 'https://raw.githubusercontent.com/liaohuqiu/umeng-libs/master/repository'
}

 

附录:Maven仓库地址收录

公有的仓库  http://repo1.maven.org/maven2/  http://repository.jboss.com/maven2/  http://repository.sonatype.org/content/groups/public/  http://mirrors.ibiblio.org/pub/mirrors/maven2/org/acegisecurity/  私有的仓库  http://repository.codehaus.org/  http://snapshots.repository.codehaus.org/  http://people.apache.org/repo/m2-snapshot-repository  http://people.apache.org/repo/m2-incubating-repository/

相关文章
相关标签/搜索