(转)搭建Maven私服(使用Nexus)
搭建私服可以做什么?
1、如果公司开发组的开发环境全部内网,这时如何连接到在互联网上的Maven中央仓库呢?
2、如果公司经常开发一些公共的组件,如何共享给各个开发组,使用拷贝方式吗?如果这样,公共库升级了怎么办?
当然可以解决的问题可能不止上面两点,下面来介绍在Linux中搭建自己的Maven私服,使用Nexus。
一、下载和安装
下载
网址:http://www.sonatype.org/nexus/go/
下载包:nexus-2.12.0-01-bundle.tar.gz
解压包:tar -zxvf nexus-2.12.0-01-bundle.tar.gz
默认端口为8081,如需修改请查看配置文件 conf/nexus.properties
它本身不建议在root用户下使用,如果我们需要在root用户下启动服务,要先配置 bin/nexus 文件中的 RUN_AS_USER=root
我下载的是zip包,解压后进入\nexus-2.1.2-bundle\nexus-2.1.2\bin\jsw\,根据操作系统类型选择文件夹,我选的是windows-x86-32文件夹,进入后可看到如下所示bat文件。
安装
将下载Bundle文件解压,会得到如下两个子目录:
nexus-webapp-1.7.2/:该目录包含了Nexus运行所需要的文件,如启动脚本,依赖jar包等。
sonatype-work/:该目录包含Nexus生成的配置文件、日志文件、仓库文件等。
其中第一个目录是运行Nexus所必需的。
第二个目录不是必须的,Nexus会在运行的时候动态创建改目录,不过它的内容对于各个Nexus实例是不一样的,因为不同用户在不同机器上使用的Nexus会有不同的配置和仓库内容。
当用户需要备份Nexus的时候,默认备份sonatype-work/目录,因为该目录包含了用户特定的内容,而nexus-webapp-1.7.2目录下的内容是可以从安装包直接获得的。
ps:最简单的方式就是将两个文件全部拷贝,然后直接安装使用。
二、私服的启动和配置
启动
[root@localhost nexus-maven]# cd nexus-2.12.0-01/bin/
[root@localhost bin]# ./nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.
[root@localhost bin]# ./nexus status
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Nexus OSS is running (34504).
[root@localhost bin]#
启动后访问首页: http://192.168.19.130:8081/nexus/index.html
登录默认账号/密码 admin/admin123
打开 Repositories 将列表中所有Type为proxy 的项目的 Configuration 中的 Download Remote Indexes 设置为True
将Releases仓库的Deployment Policy设置为*Allow ReDeploy
设置 deployment 账户密码
然后在Central 仓库上右键然后点击 Repair Index 下载中心仓库的索引文件,若干时间后,可以点击下边的 Browse Index 即可看见下载的索引文件。
当然我们也避免不了会使用到一些第三方的 jar ,而这些jar包也不存在于互联网上的maven中央仓库中,这时我们可以手工添加jar 到我们的私服中。
添加第三方 jar 如下:
如果需要删除,如下:
三、本地项目配置引用私服
在项目的 pom.xml 中配置私库地址,pom.xml 的下面添加:
<!-- 私有仓库 -->
<repositories>
<repository>
<id>public</id> <!--这个ID需要与你的组group ID一致-->
<name>Public Repository</name>
<url>http://192.168.19.130:8081/nexus/content/groups/public</url>
</repository>
</repositories> <!-- 打包发布 -->
<distributionManagement>
<repository>
<id>releases</id><!--这个ID需要与你的release仓库的Repository ID一致-->
<url>http://192.168.19.130:8081/nexus/content/repositories/releases</url>
</repository> <snapshotRepository>
<id>snapshots</id><!--这个ID需要与你的snapshots仓库的Repository ID一致-->
<url>http://192.168.19.130:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
ps:仓库也可以通过节点的方式,配置在setting.xml文件中。
在settings.xml 中配置 server 账户信息:
<servers>
<server>
<id>releases</id>
<username>deployment</username>
<password>lixuwu123</password><!--这个密码就是你设置的密码-->
</server>
<server>
<id>snapshots</id>
<username>deployment</username>
<password>lixuwu123</password><!--这个密码就是你设置的密码-->
</server>
</servers>
需要说明一点:
当pom.xml中同时配置了releases仓库和snapshots仓库时。
pom.xml文件开头的版本配置1.0.0-SNAPSHOT为build到snapshots库,
pom.xml文件开头的版本配置1.0.0 (不带-SNAPSHOT) 的会build到releases库,
如果只配置了releases库而版本号写的是带-SNAPSHOT的,build到最后一步会报400错误,因为它找不到对应的库。
四、测试
1、新建一个简单的maven项目,随便写个类。
在pom.xml 文件按上面 三、本地项目配置引用私服 方法添加 私有仓库和打包发布配置
然后使用命令 mvn deploy 发布成功后,此时我们在我们的私服中就可以看到发布后的结果,如下:
2、再新建一个项目,或者使用已有的maven项目(最好使用别人的环境不同的电脑)。
在pom.xml 中和第1步一样先配置私库地址,然后添加第1步发布后的 dependency 后,就可以看到jar 被正常加载到工程中了。
自己测试实例:
setting.xml文件
<?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:/.m2/repository</localRepository> <pluginGroups></pluginGroups> <proxies></proxies> <!-- 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.
|-->
<servers> <server>
<!-- 这个ID要和项目pom.xml中distributionManagement下的ID一致 -->
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<!-- 这个ID要和项目pom.xml中distributionManagement下的ID一致 -->
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers> <mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors> <profiles>
<profile>
<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> <!-- 激活节点nexus -->
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
pom.xml文件:
使用eclipse新建一个quickstart的maven项目
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.li</groupId>
<artifactId>test-archetype</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>test-archetype Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies> <distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement> <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build> </project>
执行命令
clean deploy

(转)搭建Maven私服(使用Nexus)的更多相关文章
- Maven学习 (四) 使用Nexus搭建Maven私服
为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给项目组人员,因此就不能使用maven访问远程的仓库地址,所以很有必要在局域网里找一台有外网权限的机器,搭建nexus私服,然后开发人员连到 ...
- Maven-004-使用 Nexus 搭建 maven 私服
从去年至今,自己一直在学习自动化测试工具,想利用自动化工具尽可能的将重复的.关键的.耗时耗力的工作实现自动化,减轻日常测试工作,提升测试效率.在学习的过程中,将 maven 作为了项目开发管理工具,进 ...
- Ubuntu server下搭建Maven私服Nexus
Ubuntu server下搭建Maven私服Nexus Maven私服Nexus的作用,主要是为了节省资源,在内部作为maven开发资源共享服务器来使用. 1.下载 通过root用户进去Ubuntu ...
- Maven使用笔记(五)Sonatype Nexus 搭建Maven 私服
1. 为什么使用Nexus 如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓库下载到本地, 而一个团队中的所有人都重复的从maven仓库下载构件无疑加大了仓库的负载 ...
- Maven——使用Nexus搭建Maven私服
原文:http://www.cnblogs.com/xdp-gacl/p/4068967.html Maven学习总结(九)--使用Nexus搭建Maven私服 一.搭建nexus私服的目的 为什么要 ...
- Maven学习 使用Nexus搭建Maven私服(转)
为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给项目组人员,因此就不能使用maven访问远程的仓库地址,所以很有必要在局域网里找一台有外网权限的机器,搭建nexus私服,然后开发人员连到 ...
- (转)Maven学习总结(九)——使用Nexus搭建Maven私服
孤傲苍狼只为成功找方法,不为失败找借口! Maven学习总结(九)——使用Nexus搭建Maven私服 一.搭建nexus私服的目的 为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给项目 ...
- Linux下使用Nexus搭建Maven私服
在开发过程中,有时候会使用到公司内部的一些开发包,显然把这些包放在外部是不合适的.另外,由于项目一直在开发中,这些内部的依赖可能也在不断的更新.可以通过搭建公司内部的Maven服务器,将第三方和内部的 ...
- Maven学习二:使用Nexus搭建Maven私服及相关配置
处于安全等原因的考虑,一些企业内部网络是不允许访问外部网络的,但是项目内部搭建的项目又是Maven架构,这样就需要企业在内部网络中搭建自己的Maven仓库服务,再者一些大型企业或者内部模块化组件化划分 ...
- Maven学习-使用Nexus搭建Maven私服
为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给项目组人员,因此就不能使用maven访问远程的仓库地址,所以很有必要在局域网里找一台有外网权限的机器,搭建nexus私服,然后开发人员连到 ...
随机推荐
- 一文让你熟练掌握Linux的ncat(nc)命令
一文让你熟练掌握Linux的ncat(nc)命令 ncat 或者说 nc 是一款功能类似 cat 的工具,但是是用于网络的.它是一款拥有多种功能的 CLI 工具,可以用来在网络上读.写以及重定向数据. ...
- M2阶段团队个人贡献分
团队个人贡献分: 徐钧鸿:53 张艺:48 黄可嵩:51 徐方宇:47 刘浩然:52 钟毅恒:49 杨伊:50
- html 空白汉字占位符 
在爬取京东评论时,复制html内容,发现文本中有些空格的宽度没见过.后来用htmlParser解析html页面时,发现这些空格都被替换为 . 12288是Unicode编码,&#表示宋体,&a ...
- 使用Java+Kotlin双语言的LeetCode刷题之路(二)
BasedLeetCode LeetCode learning records based on Java,Kotlin,Python...Github 地址 序号对应 LeetCode 中题目序号 ...
- squid反向代理
反向代理的作用是就爱那个网站中的静态自原本地化.也就是将一部分本应该有原是服务器处理的请求交给 Squid 缓存服务处理 编辑 Squid 服务程序的配置文件*(正向代理与反向代理不能同时使用,) ...
- 软件工程(GZSD2015) 第三次作业提交进度
第三次作业题目请查看这里:软件工程(GZSD2015)第三次作业 开始进入第三次作业提交进度记录中,童鞋们,虚位以待哈... 2015年4月19号 徐镇.尚清丽,C语言 2015年4月21号 毛涛.徐 ...
- JavaScript封装方法,兼容参数类型为Number和String
/** * 依据Kind确定跳转到目标列表页面. * @param kind */ function gobackByKind(kind) { var kindStr = String(kind); ...
- C语言ODBC数据库操作
今天我们来介绍一下C语言操作数据库的方法,这里我们使用的是ODBC方式.环境是WIN7+VC6.其他环境也差不多,具体情况具体分析. 首先是环境的配置以及数据源的添加.这里就不去解释了,相关资料网上有 ...
- Jmeter 通过json Extracted 来获取 指定的值的id
在没有 精确或模糊查询的接口时可以使用jmeter 获取指定的值的ID import java.lang.String ; String getTargetName="iphone632g& ...
- [转帖]Lifetime Support Stages for Your Oracle Products
Lifetime Support Stages for Your Oracle Products https://www.oracle.com/support/lifetime-support/ Pr ...