Nexus3.6安装、setting配置和jar包deploy

来源:互联网 发布:初中优化测试卷答案 编辑:程序博客网 时间:2024/06/06 08:56
1.下载
  1. http://www.sonatype.com/download-oss-sonatype

2.安装/卸载(install\uninstall)【本文以Windows环境为例】
  1. cmd进入到解压目录:E:\nexus3.6\nexus-3.6.1-02-win64\nexus-3.6.1-02\bin
  1. E:\nexus3.6\nexus-3.6.1-02-win64\nexus-3.6.1-02\bin>nexus.exe /install
  2. Installed service 'nexus'.

3.启动服务
  1. cmd窗口:输入services.msc 找到nexus服务,点击启动

4.访问端口配置
  1. 进入E:\nexus3.6\nexus-3.6.1-02-win64\nexus-3.6.1-02\etc目录,打开nexus-default.properties文件
  2. ,找到application-port=9090,修改成你自己的端口
  1. ## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
  2. ##
  3. # Jetty section
  4. application-port=8081
  5. application-host=0.0.0.0
  6. nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
  7. nexus-context-path=/
  8. # Nexus section
  9. nexus-edition=nexus-pro-edition
  10. nexus-features=\
  11. nexus-pro-feature

5.启动/停止nexus
  1. cmd窗口 -> net start nexus(启动服务)
  2. net stop nexus(停止服务)

6.访问地址
  1. http://ip:端口/
  1. 默认账号密码:admin/admin123

7.访问地仓库类型
  1. hosted 宿主仓库:主要用于部署无法从公共仓库获取的构件(如 oracle JDBC 驱动)以及自己或第三方的项目构件;
  2. proxy 代理仓库:代理公共的远程仓库;
  3. group 仓库组Nexus 通过仓库组的概念统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库。



8.配置私服(settings.xml
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  5. <!--设置的maven本地仓库-->
  6. <localRepository>D:\Java\Maven\m2\repository</localRepository>
  7. <pluginGroups/>
  8. <proxies/>
  9. <!--配置服务端的一些设置。一些设置如安全证书不应该和pom.xml一起分发。这种类型的信息应该存在于构建服务器上的settings.xml文件中。 -->
  10. <servers>
  11. <server>
  12. <!--这是serverid(注意不是用户登陆的id),iddistributionManagementrepository元素的id相匹配 -->
  13. <id>nexus</id>
  14. <!--nexus中配置的用户名密码-->
  15. <username>admin</username>
  16. <password>admin123</password>
  17. </server>
  18. <!--将项目发布到私服中需要用到-->
  19. <server>
  20. <!--这是serverid(注意不是用户登陆的id),该iddistributionManagementrepository元素的id相匹配。 -->
  21. <id>newcapec-zhifu-releases</id>
  22. <!--nexus中配置的用户名密码-->
  23. <username>admin</username>
  24. <password>admin123</password>
  25. </server>
  26. <!--将项目发布到私服中需要用到-->
  27. <server>
  28. <!--这是serverid(注意不是用户登陆的id),该iddistributionManagementrepository元素的id相匹配。 -->
  29. <id>newcapec-zhifu-snapshots</id>
  30. <!--nexus中配置的用户名密码-->
  31. <username>admin</username>
  32. <password>admin123</password>
  33. </server>
  34. </servers>
  35. <!--为仓库列表配置的下载镜像列表。 -->
  36. <mirrors>
  37. <mirror>
  38. <!--该镜像的唯一标识符。id用来区分不同的mirror元素。 -->
  39. <id>nexus</id>
  40. <!--此处配置所有的构建均从私有仓库中下载 *代表所有,也可以写central -->
  41. <mirrorOf>*</mirrorOf>
  42. <name>central repository</name>
  43. <!--该镜像的URL。构建系统会优先考虑使用该URL,而非使用默认的服务器URL -->
  44. <url>http://192.168.112.61:8081/repository/maven-public/</url>
  45. </mirror>
  46. </mirrors>
  47. <!--根据环境参数来调整构建配置的列表。settings.xml中的profile元素是pom.xmlprofile元素的裁剪版本。-->
  48. <!--它包含了idactivation, repositories, pluginRepositories properties元素。-->
  49. <!--这里的profile元素只包含这五个子元素是因为这里只关心构建系统这个整体(这正是settings.xml文件的角色定位),而非单独的项目对象模型设置。-->
  50. <!--如果一个settings中的profile被激活,它的值会覆盖任何其它定义在POM中或者profile.xml中的带有相同idprofile -->
  51. <profiles>
  52. <profile>
  53. <id>nexus</id>
  54. <!--远程仓库列表,它是Maven用来填充构建系统本地仓库所使用的一组远程项目。 -->
  55. <repositories>
  56. <!--发布版本仓库-->
  57. <repository>
  58. <id>nexus</id>
  59. <!--name随便-->
  60. <name>Nexus Release Snapshot Repository</name>
  61. <!--地址是nexusrepositoryReleases/Snapshots)中对应的地址-->
  62. <url>http://192.168.112.61:8081/repository/maven-releases/</url>
  63. <!--true或者false表示该仓库是否为下载某种类型构件(发布版,快照版)开启。 -->
  64. <releases>
  65. <enabled>true</enabled>
  66. </releases>
  67. <snapshots>
  68. <enabled>true</enabled>
  69. </snapshots>
  70. </repository>
  71. </repositories>
  72. <!--发现插件的远程仓库列表。仓库是两种主要构件的家。第一种构件被用作其它构件的依赖。这是中央仓库中存储的大部分构件类型。另外一种构件类型是插件。-->
  73. <!--各节点的含义和repository是一样的-->
  74. <pluginRepositories>
  75. <pluginRepository>
  76. <id>nexus</id>
  77. <name>Nexus Release Snapshot Repository</name>
  78. <url>http://192.168.112.61:8081/repository/maven-releases/</url>
  79. <releases>
  80. <enabled>true</enabled>
  81. </releases>
  82. <snapshots>
  83. <enabled>true</enabled>
  84. </snapshots>
  85. </pluginRepository>
  86. </pluginRepositories>
  87. </profile>
  88. <!--设置maven编译器级别-->
  89. <profile>
  90. <id>jdk18</id>
  91. <activation>
  92. <!--profile默认是否激活的标识 -->
  93. <activeByDefault>true</activeByDefault>
  94. <!--activation有一个内建的java版本检测,如果检测到jdk版本与期待的一样,profile被激活。 -->
  95. <jdk>1.8</jdk>
  96. </activation>
  97. <properties>
  98. <maven.compiler.source>1.8</maven.compiler.source>
  99. <maven.compiler.target>1.8</maven.compiler.target>
  100. <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
  101. </properties>
  102. </profile>
  103. </profiles>
  104. <!--激活配置-->
  105. <activeProfiles>
  106. <!--profile下的id-->
  107. <activeProfile>nexus</activeProfile>
  108. </activeProfiles>
  109. </settings>

9.上传jar包到Nexus

  • pom方式:
  1. pom.xml中添加,和dependencies属于同一级别,在project级别下
  1. <!--将项目发布到私服中--><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>
  1. id为要上传的repository的唯一标示,url为要上传的repository的路径
  1. mvn deploy即可

 

 
  • 命令方式:
  1. mvn deploy:deploy-file -DgroupId=xxx.xxx -DartifactId=xxx -Dversion=0.0.2 -Dpackaging=jar 
  2. -Dfile=D:\xxx.jar -Durl=http://xxx.xxx.xxx.xxx:8081/repository/3rdParty/ -DrepositoryId=3rdParty
  1. 其中-DgroupId 为上传的jargroupId
  2. -DartifactId 为上传的jarartifactId
  3. -Dversion 为上传的jar的需要被依赖的时候的版本号
  4. 然后是-Dpackagingjar,-Dfilejar包路径
  5. -Durl 为要上传的路径,可以通过以下方式获取到
  6. -DrepositoryId repository的唯一标示,跟第二步中赋权配置的server相同
参考来源:http://blog.csdn.net/iopfan/article/details/71107686
原创粉丝点击