(转)搭建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私服,然后开发人员连到 ...
随机推荐
- Mvc_ActionResult返回值
//ViewResult 表示HTML的页面内容 //EmptyResult 表示空白的页面内容 //RedirectResult 表示定位到另外一个URL //JsonResult 表示可以运用到A ...
- kvm虚拟化管理平台WebVirtMgr部署-完整记录(3)
继下面三篇文章完成了kvm虚拟化管理平台webvirtmgr环境的部署安装:kvm虚拟化管理平台WebVirtMgr部署-虚拟化环境安装-完整记录(0)kvm虚拟化管理平台WebVirtMgr部署-完 ...
- Centos6下关于系统用户密码规则-运维笔记
随着linux使用的普遍,对于linux用户以及系统的安全要求越来越高,而用户密码复杂程度是系统安全性高低的首要体现.因此如何对linux下用户的密码进行规则限制,以保证用户必须使用复杂的密码,杜绝用 ...
- js怎么将 base64转换成图片
//获取数组最后一个元素 let hasFiles = files[Object.keys(files).pop()] // 参考上面的图片 let file = hasFiles.url let n ...
- doc窗口 输入命令net start mysql 服务名无效
解决方案: 1.win+R键输入cmd敲回车进入dos界面: 2.输入cd d:/mysql-5.5.25/bin敲回车,发现没变化: 3.输入d:敲回车,定位到d:\mysql-5.5.25\bin ...
- 第三个Sprint冲刺第3天
成员:罗凯旋.罗林杰.吴伟锋.黎文衷 组内各成员加紧完成自己的工作.
- pandas(DataFrame)
DataFrame是二维数据结构,即数据以行和列的表格方式排列!特点:潜在的列是不同的类型,大小可变,标记行和列,可以对列和行执行算数运算. 其中Name,Age即为对应的Columns,序号0,1, ...
- 【转】STM32 独立看门狗简介
STM32 的独立看门狗由内部专门的 40Khz 低速时钟驱动,即使主时钟发生故障,它也仍然有效. 看门狗的原理:单片机系统在外界的干扰下会出现程序跑飞的现象导致出现死循环,看门狗电路就是为了避免这种 ...
- Jenkins and Python
https://jenkins.io/solutions/python/ In the Python ecosystem there are tools which can be integrated ...
- Exception while invoking TaskListener: Exception while invoking TaskListener: null
https://community.alfresco.com/thread/225041-exception-while-invoking-tasklistener-null Ok, so the p ...