1.下载
http://www.sonatype.com/download-oss-sonatype
2.安装/卸载(install\uninstall)【本文以Windows环境为例】
cmd进入到解压目录:E:\nexus3.6\nexus-3.6.1-02-win64\nexus-3.6.1-02\bin
E:\nexus3.6\nexus-3.6.1-02-win64\nexus-3.6.1-02\bin>nexus.exe /installInstalled service 'nexus'.
3.启动服务
cmd窗口:输入services.msc 找到nexus服务,点击启动
4.访问端口配置
进入E:\nexus3.6\nexus-3.6.1-02-win64\nexus-3.6.1-02\etc目录,打开nexus-default.properties文件,找到application-port=9090,修改成你自己的端口
## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties### Jetty sectionapplication-port=8081application-host=0.0.0.0nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xmlnexus-context-path=/# Nexus sectionnexus-edition=nexus-pro-editionnexus-features=\nexus-pro-feature
5.启动/停止nexus
cmd窗口 -> net start nexus(启动服务)net stop nexus(停止服务)
6.访问地址
http://ip:端口/
默认账号密码:admin/admin123
7.访问地仓库类型
hosted 宿主仓库:主要用于部署无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)以及自己或第三方的项目构件;proxy 代理仓库:代理公共的远程仓库;group 仓库组:Nexus 通过仓库组的概念统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库。

8.配置私服(settings.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"><!--设置的maven本地仓库--><localRepository>D:\Java\Maven\m2\repository</localRepository><pluginGroups/><proxies/><!--配置服务端的一些设置。一些设置如安全证书不应该和pom.xml一起分发。这种类型的信息应该存在于构建服务器上的settings.xml文件中。 --><servers><server><!--这是server的id(注意不是用户登陆的id),该id与distributionManagement中repository元素的id相匹配。 --><id>nexus</id><!--nexus中配置的用户名密码--><username>admin</username><password>admin123</password></server><!--将项目发布到私服中需要用到--><server><!--这是server的id(注意不是用户登陆的id),该id与distributionManagement中repository元素的id相匹配。 --><id>newcapec-zhifu-releases</id><!--nexus中配置的用户名密码--><username>admin</username><password>admin123</password></server><!--将项目发布到私服中需要用到--><server><!--这是server的id(注意不是用户登陆的id),该id与distributionManagement中repository元素的id相匹配。 --><id>newcapec-zhifu-snapshots</id><!--nexus中配置的用户名密码--><username>admin</username><password>admin123</password></server></servers><!--为仓库列表配置的下载镜像列表。 --><mirrors><mirror><!--该镜像的唯一标识符。id用来区分不同的mirror元素。 --><id>nexus</id><!--此处配置所有的构建均从私有仓库中下载 *代表所有,也可以写central --><mirrorOf>*</mirrorOf><name>central repository</name><!--该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL。 --><url>http://192.168.112.61:8081/repository/maven-public/</url></mirror></mirrors><!--根据环境参数来调整构建配置的列表。settings.xml中的profile元素是pom.xml中profile元素的裁剪版本。--><!--它包含了id,activation, repositories, pluginRepositories和 properties元素。--><!--这里的profile元素只包含这五个子元素是因为这里只关心构建系统这个整体(这正是settings.xml文件的角色定位),而非单独的项目对象模型设置。--><!--如果一个settings中的profile被激活,它的值会覆盖任何其它定义在POM中或者profile.xml中的带有相同id的profile。 --><profiles><profile><id>nexus</id><!--远程仓库列表,它是Maven用来填充构建系统本地仓库所使用的一组远程项目。 --><repositories><!--发布版本仓库--><repository><id>nexus</id><!--name随便--><name>Nexus Release Snapshot Repository</name><!--地址是nexus中repository(Releases/Snapshots)中对应的地址--><url>http://192.168.112.61:8081/repository/maven-releases/</url><!--true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 --><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositories><!--发现插件的远程仓库列表。仓库是两种主要构件的家。第一种构件被用作其它构件的依赖。这是中央仓库中存储的大部分构件类型。另外一种构件类型是插件。--><!--各节点的含义和repository是一样的--><pluginRepositories><pluginRepository><id>nexus</id><name>Nexus Release Snapshot Repository</name><url>http://192.168.112.61:8081/repository/maven-releases/</url><releases><enabled>true</enabled></releases><snapshots><enabled>true</enabled></snapshots></pluginRepository></pluginRepositories></profile><!--设置maven编译器级别--><profile><id>jdk18</id><activation><!--profile默认是否激活的标识 --><activeByDefault>true</activeByDefault><!--activation有一个内建的java版本检测,如果检测到jdk版本与期待的一样,profile被激活。 --><jdk>1.8</jdk></activation><properties><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></properties></profile></profiles><!--激活配置--><activeProfiles><!--profile下的id--><activeProfile>nexus</activeProfile></activeProfiles></settings>
9.上传jar包到Nexus
- pom方式:
pom.xml中添加,和dependencies属于同一级别,在project级别下
<!--将项目发布到私服中--> <distributionManagement> <repository> <id>newcapec-zhifu-releases</id> <name>newcapec-zhifu-releases</name> <url>http://192.168.112.61:8081/repository/newcapec-zhifu-releases/</url> </repository> <snapshotRepository> <id>newcapec-zhifu-snapshots</id> <name>newcapec-zhifu-snapshots</name> <url>http://192.168.112.61:8081/repository/newcapec-zhifu-snapshots/</url> </snapshotRepository> </distributionManagement>
id为要上传的repository的唯一标示,url为要上传的repository的路径
mvn deploy即可


- 命令方式:
mvn deploy:deploy-file -DgroupId=xxx.xxx -DartifactId=xxx -Dversion=0.0.2 -Dpackaging=jar-Dfile=D:\xxx.jar -Durl=http://xxx.xxx.xxx.xxx:8081/repository/3rdParty/ -DrepositoryId=3rdParty
其中-DgroupId 为上传的jar的groupId-DartifactId 为上传的jar的artifactId-Dversion 为上传的jar的需要被依赖的时候的版本号然后是-Dpackaging为jar,-Dfile为jar包路径-Durl 为要上传的路径,可以通过以下方式获取到-DrepositoryId 为repository的唯一标示,跟第二步中赋权配置的server相同
参考来源:http://blog.youkuaiyun.com/iopfan/article/details/71107686
本文详细介绍如何在Windows环境下安装并配置Nexus仓库管理器,包括下载、安装、启动服务、端口配置及访问等步骤,并指导如何设置私服、上传jar包及配置settings.xml文件。
1422

被折叠的 条评论
为什么被折叠?



