我之前maven一直downloading用公司的maven私服,现在我在自己电脑上配了私服,请问怎样可以把公司私服仓库里的包导入

Mac下使用Nexus搭建Maven私服_MAC教程-织梦者
当前位置:&>&&>& > Mac下使用Nexus搭建Maven私服
Mac下使用Nexus搭建Maven私服
原文地址:https://my.oschina.net/u/873661/blog/195373
我们可以在nexus的官网上找到它的相关介绍,下载地址是http://www.sonatype.org/nexus/go,在这里可以找到最新的版本,如果需要以前的版本,在这里也可以找到下载地址。Nexus提供了两种安装方式,一种是内嵌Jetty的bundle,只要你有JRE就能直接运行。第二种方式是WAR,你只须简单的将其发布到web容器中即可使用。为了方便就直接选用bundle版本。我下载的是:nexus-2.2-bundle.tar.gz。
在指定的目录解压下载的文件。解压后会看到两个文件夹,分别是nexus-2.2-01和sonatype-work,前者包含了nexus的运行环境和应用程序,后者包含了你自己的配置和存储构件的地方。nexus-2.2-01/conf/nexus.properties中可以修改端口信息以及工作区的路径。
3.启动nexus
进入nexus-2.2-01/bin/jsw/目录,然后根据OS的版本进入相应的目录,在linux下,运行./nexus start即启动了服务,直接运行./nexus会看到提示信息,运行./nexus console 可以以控制台方式启动nexus,方便我们观察启动时的相关工作。neuxs默认监听端口是8081,此时在中运行访问http://127.0.0.1:8081/nexus或者http://localhost:8081/nexus或者http://0.0.0.0:8081/nexus应该可以看到neuxs的界面。
新搭建的neuxs环境只是一个空的仓库,需要手动和远程中心库进行同步,nexus默认是关闭远程索引下载,最重要的一件事情就是开启远程索引下载。登陆nexus系统,默认用户名密码为admin/admin123。 点击左边Views/Repositories菜单下面的Repositories,找到右边仓库列表中的三个仓库Apache
Snapshots,Codehaus Snapshots和Central,然后再没有仓库的Configuration下把Download Remote Indexes修改为true。然后在这三个仓库上分别右键,选择Repari Index,这样Nexus就会去下载远程的索引文件。
新建公司的内部仓库,步骤为Repositories –& Add –& Hosted Repository,在页面的下半部分输入框中填入Repository ID和Repository Name即可,比如分别填入myrepo和 my repository,另外把Deployment Policy设置为Allow Redeploy,点击save就创建完成了。
修改nexus仓库组
Nexus中仓库组的概念是Maven没有的,在Maven看来,不管你是hosted也好,proxy也好,或者group也好,对我都是一样的,我只管根据groupId,artifactId,version等信息向你要构件。为了方便Maven的配置,Nexus能够将多个仓库,hosted或者proxy合并成一个group,这样,Maven只需要依赖于一个group,便能使用所有该group包含的仓库的内容。
neuxs-2.2中默认自带了一个名为“Public Repositories”组,点击该组可以对他保护的仓库进行调整,把刚才建立的公司内部仓库加入其中,这样就不需要再在maven中明确指定内部仓库的地址了。同时创建一个Group ID为public-snapshots、Group Name为Public Snapshots Repositories的组,把Apache Snapshots、Codehaus Snapshots和Snapshots加入其中。
到这里neuxs的安装配置就完成了,下面介绍如何在maven中使用自己的私服。
maven安装好默认是没有配置仓库信息,此时maven都默认去远程的中心仓库下载所依赖的构件。既然使用了私服,就需要明确告诉maven去哪里下载构件,可以在三个地方进行配置,分别是maven的安装目录下的conf下的settings.xml文件,这个全局配置,再一个是在userprofile/.m2目录下的settings.xml,如果不存在该文件,可以复制conf下settings.xml,这个是针对当前用户的,还有一个是在pom.xml中指定,其只对该项目有效,三个文件的优先级是pom.xml大于.m2,.m2大于conf下。
settings.xml的配置如下:
在profiles段增加一个profile
&id&nexus&/id&
&repositories&
&repository&
&id&nexus&/id&
&name&localprivatenexus&/name&
&url&http://192.168.1.68:8081/nexus/content/groups/public&/url&
&releases&&enabled&true&/enabled&&/releases&
&snapshots&&enabled&false&/enabled&&/snapshots&
&/repository&
&repository&
&id&nexus-snapshots&/id&
&name&localprivatenexus&/name&
&url&http://192.168.1.68:8081/nexus/content/groups/public-snapshots&/url&
&releases&&enabled&false&/enabled&&/releases&
&snapshots&&enabled&true&/enabled&&/snapshots&
&/repository&
&/repositories&
&pluginRepositories&
&pluginRepository&
&id&nexus&/id&
&name&localprivatenexus&/name&
&url&http://192.168.1.68:8081/nexus/content/groups/public&/url&
&releases&&enabled&true&/enabled&&/releases&
&snapshots&&enabled&false&/enabled&&/snapshots&
&/pluginRepository&
&pluginRepository&
&id&nexus-snapshots&/id&
&name&localprivatenexus&/name&
&url&http://192.168.1.68:8081/nexus/content/groups/public-snapshots&/url&
&releases&&enabled&false&/enabled&&/releases&
&snapshots&&enabled&true&/enabled&&/snapshots&
&/pluginRepository&
&/pluginRepositories&
&/profile&
上述的id,name可以根据自己的喜好来定义,保证多个repository的id不重复即可,主要是url的配置,可以在nexus的repositories列表中找到对应的url,就是repositories的Repository Path,刚才我们已经在neuxs中定义了仓库组,这里就取对应组的Repository Path信息即可。
另外,仓库是两种主要构件的家。第一种构件被用作其它构件的依赖。这是中央仓库中存储的大部分构件类型。另外一种构件类型是插件。如果不配置pluginRepositories,那么执行maven动作时,还是会看到去远程中心库下载需要的插件构件,所以这里一定要加上这个。
在settings.xml中指使配置了profile还不行,需要激活它,在activeProfiles段,增加如下配置:
&activeProfile&nexus&/activeProfile&
此处activeProfile中的内容就上面定义profile的id。
pom.xml配置如下:
&repositories&
&repository&
&id&nexus&/id&
&name&localprivatenexus&/name&
&url&http://192.168.1.68:8081/nexus/content/groups/public&/url&
&releases&
&enabled&true&/enabled&
&/releases&
&snapshots&
&enabled&false&/enabled&
&/snapshots&
&/repository&
&repository&
&id&nexus-snapshots&/id&
&name&localprivatenexus&/name&
&url&http://192.168.1.68:8081/nexus/content/groups/public-snapshots&/url&
&releases&
&enabled&false&/enabled&
&/releases&
&snapshots&
&enabled&true&/enabled&
&/snapshots&
&/repository&
&/repositories&
&pluginRepositories&
&pluginRepository&
&id&nexus&/id&
&name&localprivatenexus&/name&
&url&http://192.168.1.68:8081/nexus/content/groups/public&/url&
&releases&
&enabled&true&/enabled&
&/releases&
&snapshots&
&enabled&false&/enabled&
&/snapshots&
&/pluginRepository&
&pluginRepository&
&id&nexus-snapshots&/id&
&name&localprivatenexus&/name&
&url&http://192.168.1.68:8081/nexus/content/groups/public-snapshots&/url&
&releases&
&enabled&false&/enabled&
&/releases&
&snapshots&
&enabled&true&/enabled&
&/snapshots&
&/pluginRepository&
&/pluginRepositories&
其中id,name都无所谓,关键不能把url弄错。
有了上述配置,当在项目执行maven操作时,如果本地库中没有依赖的构件,maven会去私服下载,如果私服也没有,私服会去远程中心库下载,同时会在私服的本地缓存,这样如果第二个人再要用到这个构件,私服就直接提供下载。
以上就是Mac下使用Nexus搭建Maven私服的全文介绍,希望对您学习mac开发和使用有所帮助.
这些内容可能对你也有帮助
更多可查看MAC教程列表页。
猜您也会喜欢这些文章windows下使用nexus搭建maven私服的流程和说明
1、下载nexus:
没什么难的,下载一个oss版本,即open
source开源版,&。
2、将下载的zip包或者tgz包解压出来:
如图所示,nexus默认的工作目录为统计目录下的sonatype-work目录,可以在%nexus_home%/conf/nexus.properties中进行修改。
工作目录的作用:最主要是存储,所有的仓库索引文件、插件索引文件都存在工作目录中(storage、plugin-repository目录);另外就是存储系统日志(log文件夹)。因此,工作目录应该设置为磁盘空间较大的目录。
3、启动nexus:
%nexus_home%/bin/js/下找到操作系统对应的脚本console-nexus.bat,运行即可。
nexus默认使用内置的jetty服务器,文件夹中其他的脚本,根据名称很容易理解,无非是安装成windows服务,其他服务、停止服务、卸载服务等。
4、登录并修改密码:
nexus默认的管理员账号为admin,密码admin123,可以通过左侧菜单security-user来修改密码。
5、仓库管理:
点击菜单栏的view/repostories-repostories菜单,进入仓库界面:
(1)仓库类型:
hosted:宿主仓库,其实就是本地的仓库
proxy:代理仓库,就是当前私服代理了其他的第三方仓库或Apache的中央仓库
virtual:虚拟仓库
group:多个仓库可以组成一个组,使用组就相当于在使用组内的仓库成员的资源
(2)说明:
如图的界面所示,nexus默认有一个仓库组(public
repositories),其配置可以通过它的configuration子标签页查看:
可以看到,这个组里边默认有本地的releases、snapsots、3rd
party库,同时还有central库,这些仓库的顺序决定了查找资源的顺序,所以最好将本地的放在前边。
releases库,系统默认的库,存放本地部署的release版包;
snapshots库,系统默认库,存放本地的snapshot版包;
party库,系统默认库,存放第三方包;
central库,代理Apache中间仓库。
到这里,我们的私服已经可以使用了。
6、使用仓库:
(1)修改maven的配置文件:
找到maven的配置文件(这里我直接修改%M2_HOME%/conf/setting.xml文件),找到节点,添加一个镜像节点:
id:镜像的位唯一标示
mirrorOf:代理哪些仓库,*为所有的资源都从本maven私服获取
url:及新搭建的私服的默认仓库组的url地址(通过页面可以查看)
同样,在节点配置一个节点和Repostory节点。
ok,配置完成,接下来,我们可以在项目的pom.xml中配置需要的jar包,如果本地没有,则会到我们搭建的私服中找其索引文件,并并下载到本地,如果私服没有,则会去仓库组中找(确切的说是仓库组配置的Apache中央仓库去找),找到并将索引文件保存到私服中,将jar包下载到本地仓库中。
因此,我们没必要将中央仓库的所有索引下下来,而是使用到的时候会自动下载。
7、如何发布本地的jar包到私服中?
(1)配置授权:
在maven的配置文件(这里我直接修改%M2_HOME%/conf/setting.xml文件)中,找到节点,添加两个server配置:
id:必须与项目的pom中配置distributionManagement的中的id相同,唯一标示,这里的release表示发布release版本的包到release仓库,而snapshot表示发布snapshot版本的包到snapshot仓库;
username:具有私服发布包权限的用户的User
ID,具体见私服的权限和用户说明
password:当然是用户的密码。
&font style="font-size:
16"&&b&(2)在项目的pom.xml配置文件中,配置发布的地址信息:&\/b&&\/font&
&font style="font-size: 16"&&a
href="http://photo..cn/showpic.html#blogid=6c969b4a0102vlf6&url=.cn/pic/001Zi7RUgy6QNt6DCUcfc"
target="_blank"&&img
src="/mw690/001Zi7RUgy6QNt6DCUcfc&690"
width="690" height="211"
id="image_operate_43242"&&\/a&&br&&br&&\/font&
id:与(1)中配置授权时的id一致;
url:私服对应的仓库的url地址。其实,这部分信息在私服仓库子标签页summary可以查看:
&font style="font-size:
16"&&b&(3)ok,配置完成&\/b&&\/font&
可以发布你的jar包到私服中了,如果项目的pom.xml中,version属性有SNAPSHOT表示为快照版,则会发布到snapshot仓库中,否则,发布到release仓库中。
&font style="font-size:
18"&&b&注意事项总结:&\/b&&\/font&
1、私服不会下载中央仓库的所有jar包,而是下载其索引文件,最终的jar包还是来自中央仓库或第三方仓库;
2、不需要一开始就下载中央仓库的索引文件,该文件很大,而是使用过程中逐渐下载;
3、注意仓库组的概念,一般来说默认的组已经完全够用了,按照需要,可以自己建立需要的仓库。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。搭建Maven私服 - 服务器技术综合 - 次元立方网 - 电脑知识与技术互动交流平台
搭建Maven私服
  最近公司人事变革,一批人员被离职,瞬间感觉压力大增,我一个做android,想要顶起后台接口的活,真是有点吃力,已经30了,还在各种苦逼,但是做为技术控,这种快乐别人无法理解。这几天Check Out后台代码,无奈跑不起来,Mac系统Maven构建实在蛋疼,于是恨起来后台组的哥们为什么不搭建Maven私服,好吧还是交给我来做好了,能者多劳,在这家公司这句话体现的淋漓尽致,废话不说了,在服务器上建的已经成功,就随便找台机子再练习一遍顺道写个日志。
1、前往/download-oss-sonatype下载Nexus-Bundle
  下载地址:http://www.sonatype.org/downloads/nexus-latest-bundle.zip
2、解压下载的nexus-2.13.0-01-bundle
3、安装并nexus服务
  更改nexus服务端口(可选步骤)
  这里使用默认端口 8081
5、修改用户Maven配置文件,%userprofile%.m2setting.xml
  Content of setting.xml (You should replace `username`,`pass` & `url` in the file if you have changed them.)
&id&releases&/id&
&username&admin&/username&
&pass&adminsa&/password&
&id&snapshots&/id&
&username&admin&/username&
&password&adminsa&/password&
&/servers&
&id&nexus&/id&
&mirrorOf&*&/mirrorOf&
&url&http://127.0.0.1:8081/nexus/content/groups/public/&/url&
&/mirrors&
&profiles&
&id&nexus&/id&
&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&
&activeProfile&nexus&/activeProfile&
&/activeProfiles&
6、客户端配置(假定已经配置好Maven运行环境)
  为pom.xml添加Maven私服配置
  Content of add item
&repositories&
&repository&
&id&nexus&/id&
&name&Team Nexus Repository&/name&
&url&http://127.0.0.1:8081/nexus/content/groups/public&/url&
&/repository&
&/repositories&
&pluginRepositories&
&pluginRepository&
&id&nexus&/id&
&name&Team Nexus Repository&/name&
&url&http://127.0.0.1:8081/nexus/content/groups/public&/url&
&/pluginRepository&
&/pluginRepositories&
7、客户端测试(需要有Maven项目,没有点击下载 A Simple Maven Project)
  进入到Maven项目目录(pom.xml所在目录)
8、验证Maven私服(Repositories -& Repository Path[Central])
9、看到刚刚使用 mvn clean命令下载的plexus-utils-3.0已经在私服仓库中,这时如果局域网内其他机器测试就会直接从私服上下载,为项目构建节省资源。
  可以看到在另一台机器上已经下载一上午的结果(Mac系统有时候让人很无语)
  再看看修改了pom.xml后再看看构建是个什么样子吧
  构建完成,是不是感觉用起来很爽,值得一提的是,其他客户机上同样需要在用户目录的.m2子目录中创建setting.xml配置上Maven私服。在Intellij Idea上直接 update indecies还不行,明明已经配置了使用下载的Maven,原因正在调查中。
延伸阅读:
这篇文章,可能比较长,如果你觉得写得好可以把它看完...
本教程为 李华明 编著的iOS-Cocos2d游戏开发系列教程:教程涵盖关于i......
专题主要学习DirectX的初级编程入门学习,对Directx11的入门及初学者有......
&面向对象的JavaScript&这一说法多少有些冗余,因为JavaScript 语言本......
Windows7系统专题 无论是升级操作系统、资料备份、加强资料的安全及管......maven无法从私服下载依赖 - ITeye问答
我在pom.xml里面配置了
&distributionManagement&
&repository&
&id&thirdparty&/id&
&url&http://192.168.9.16:8000/nexus/content/repositories/thirdparty&/url&
&/repository&
&/distributionManagement&
我的目的是想
下载依赖的时候,优先去私服下载,私服没有,就去公网下载
但是,这样不起作用,maven总是去公网下载。
请问,什么问题。
采纳的答案
你这个代码并不是配置私服仓库,而且配置部署构建到私服。应该是这样的。
&repositories&
&&&&&&& &repository&
&&&&&&&&&&& &id&nexus&/id&
&&&&&&&&
&&&&&&&&&&& &url&http://192.168.9.16:8000/nexus/content/repositories/thirdparty&/url&
&&&&&&&&&&& &layout&default&/layout&
&&&&&&& &/repository&
&&&&&&& &repository&
&&&&&&&&&&& &id&maven&/id&
&&&&&&&&&&& &name&Maven Repository Switchboard&/name&
&&&&&&&&&&& &layout&default&/layout&
&&&&&&&&&&& &url&http://repo1.maven.org/maven2&/url&
&&&&&&& &/repository&
&&& &/repositories&
已解决问题
未解决问题

我要回帖

更多关于 maven环境变量配置 的文章

 

随机推荐