1. 私服简介
私服是指私有服务器,是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构建。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。
2. nexus3的环境安装
下载地址:https://www.sonatype.com/download-oss-sonatype
解压后如下:
3. nexus3的启动
配置完成后,打开cmd或者powershell,进入nexus-3.0.1-01in下。
执行:nexus.exe /run
注意斜杠
最后经过一大轮的日志打印,最后出现如下界面,说明nexus私服已经搭建好了
启动成功后,默认用户名admin 密码:admin123
配置路径:D:server exus-3.3.2-02-win64sonatype-work exus3dbsecurityuser.pcl
密码重置:
找到这个地方:admin^ZAdministrator^HUser^Lactive&tianya@zifangdt.com<8c>^B$shiro1$SHA- 512$1024$NE+wqQq/TmjZMvfI7ENh/g==$V4yPw8T64UQ6GfJfxYq2hLsVrBY8D1v+bktfOxGdt4b/9BthpWPNUy/CBk6V9iA0nHpzYzJFWO8v/tZFtES8CA==
将1024后面的131个字符删除掉,然后用上述131个字符替换
端口:默认8081
端口配置文件:D:server exus-3.3.2-02-win64 exus-3.3.2-02etc exus-default.properties 之类的,若在:D:server exus-3.3.2-02-win64sonatype-work exus3etc exus.properties启用,则覆盖前者配置
废话不多说,访问路径:localhost:8081
4. component的介绍
component name的一些说明:
- maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar
- maven-releases:私库发行版jar
- maven-snapshots:私库快照(调试版本)jar
- maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。
component type的一些说明:
- hosted:类型的仓库,内部项目的发布仓库
- releases:内部的模块中release模块的发布仓库
- snapshots:发布内部的SNAPSHOT模块的仓库
- 3rd party:第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去
- proxy:类型的仓库,从远程中央仓库中寻找数据的仓库
5. maven的settings配置文件
注意一般起效果的配置文件路径:C:UsersAdministrator.m2settings.xml 在maven的安装目录下的文件好像不起作用。切记切记
一下是笔者的配置文件,有点多,有时间整理一下,包含了号称史上最快的私服,阿里私服。全文献上!
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <!-- 4 Licensed to the Apache Software Foundation (ASF) under one 5 or more contributor license agreements. See the NOTICE file 6 distributed with this work for additional information 7 regarding copyright ownership. The ASF licenses this file 8 to you under the Apache License, Version 2.0 (the 9 "License"); you may not use this file except in compliance 10 with the License. You may obtain a copy of the License at 11 12 http://www.apache.org/licenses/LICENSE-2.0 13 14 Unless required by applicable law or agreed to in writing, 15 software distributed under the License is distributed on an 16 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 KIND, either express or implied. See the License for the 18 specific language governing permissions and limitations 19 under the License. 20 --> 21 22 <!-- 23 | This is the configuration file for Maven. It can be specified at two levels: 24 | 25 | 1. User Level. This settings.xml file provides configuration for a single user, 26 | and is normally provided in ${user.home}/.m2/settings.xml. 27 | 28 | NOTE: This location can be overridden with the CLI option: 29 | 30 | -s /path/to/user/settings.xml 31 | 32 | 2. Global Level. This settings.xml file provides configuration for all Maven 33 | users on a machine (assuming they're all using the same Maven 34 | installation). It's normally provided in 35 | ${maven.home}/conf/settings.xml. 36 | 37 | NOTE: This location can be overridden with the CLI option: 38 | 39 | -gs /path/to/global/settings.xml 40 | 41 | The sections in this sample file are intended to give you a running start at 42 | getting the most out of your Maven installation. Where appropriate, the default 43 | values (values used when the setting is not specified) are provided. 44 | 45 |--> 46 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 47 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 48 xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> 49 <!-- localRepository 50 | The path to the local repository maven will use to store artifacts. 51 | 52 | Default: ${user.home}/.m2/repository --> 53 <localRepository>C:/path/to/local/repo</localRepository> 54 55 56 <!-- interactiveMode 57 | This will determine whether maven prompts you when it needs input. If set to false, 58 | maven will use a sensible default value, perhaps based on some other setting, for 59 | the parameter in question. 60 | 61 | Default: true 62 <interactiveMode>true</interactiveMode> 63 --> 64 65 <!-- offline 66 | Determines whether maven should attempt to connect to the network when executing a build. 67 | This will have an effect on artifact downloads, artifact deployment, and others. 68 | 69 | Default: false 70 <offline>false</offline> 71 --> 72 73 <!-- pluginGroups 74 | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e. 75 | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers 76 | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list. 77 |--> 78 <pluginGroups> 79 <!-- pluginGroup 80 | Specifies a further group identifier to use for plugin lookup. 81 <pluginGroup>com.your.plugins</pluginGroup> 82 --> 83 <pluginGroup>org.sonatype.plugins</pluginGroup> 84 <pluginGroup>org.mortbay.jetty</pluginGroup> 85 </pluginGroups> 86 87 <!-- proxies 88 | This is a list of proxies which can be used on this machine to connect to the network. 89 | Unless otherwise specified (by system property or command-line switch), the first proxy 90 | specification in this list marked as active will be used. 91 |--> 92 <proxies> 93 <!-- proxy 94 | Specification for one proxy, to be used in connecting to the network. 95 | 96 <proxy> 97 <id>optional</id> 98 <active>true</active> 99 <protocol>http</protocol> 100 <username>proxyuser</username> 101 <password>proxypass</password> 102 <host>proxy.host.net</host> 103 <port>80</port> 104 <nonProxyHosts>local.net|some.host.com</nonProxyHosts> 105 </proxy> 106 --> 107 </proxies> 108 109 <!-- servers 110 | This is a list of authentication profiles, keyed by the server-id used within the system. 111 | Authentication profiles can be used whenever maven must make a connection to a remote server. 112 |--> 113 <servers> 114 <!-- server 115 | Specifies the authentication information to use when connecting to a particular server, identified by 116 | a unique name within the system (referred to by the 'id' attribute below). 117 | 118 | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are 119 | used together. 120 | 121 <server> 122 <id>deploymentRepo</id> 123 <username>repouser</username> 124 <password>repopwd</password> 125 </server> 126 --> 127 128 <!-- Another sample, using keys to authenticate. 129 <server> 130 <id>siteServer</id> 131 <privateKey>/path/to/private/key</privateKey> 132 <passphrase>optional; leave empty if not used.</passphrase> 133 </server> 134 --> 135 <server> 136 <id>nexus</id> 137 <username>admin</username> 138 <password>admin123</password> 139 </server> 140 <server> 141 <id>ali</id> 142 <username>ali</username> 143 <password>ali</password> 144 </server> 145 <server> 146 <id>Snapshots</id> 147 <username>ali</username> 148 <password>ali</password> 149 </server> 150 </servers> 151 152 <!-- mirrors 153 | This is a list of mirrors to be used in downloading artifacts from remote repositories. 154 | 155 | It works like this: a POM may declare a repository to use in resolving certain artifacts. 156 | However, this repository may have problems with heavy traffic at times, so people have mirrored 157 | it to several places. 158 | 159 | That repository definition will have a unique id, so we can create a mirror reference for that 160 | repository, to be used as an alternate download site. The mirror site will be the preferred 161 | server for that repository. 162 |--> 163 <mirrors> 164 <!-- mirror 165 | Specifies a repository mirror site to use instead of a given repository. The repository that 166 | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used 167 | for inheritance and direct lookup purposes, and must be unique across the set of mirrors. 168 | 169 <mirror> 170 <id>mirrorId</id> 171 <mirrorOf>repositoryId</mirrorOf> 172 <name>Human Readable Name for this Mirror.</name> 173 <url>http://my.repository.com/repo/path</url> 174 </mirror> 175 --> 176 <mirror> 177 <id>nexus</id> 178 <mirrorOf>*</mirrorOf> 179 <url>http://localhost:8081/repository/maven-public/</url> 180 </mirror> 181 <mirror> 182 <!--This sends everything else to /public --> 183 <id>ali</id> 184 <mirrorOf>*</mirrorOf> 185 <url>http://maven.aliyun.com/nexus/content/groups/public/</url> 186 </mirror> 187 <mirror> 188 <!--This is used to direct the public snapshots repo in the 189 profile below over to a different nexus group --> 190 <id>nexus-public-snapshots</id> 191 <mirrorOf>public-snapshots</mirrorOf> 192 <!-- 193 <url>http://10.58.120.19:8058/nexus/content/repositories/snapshots</url> 194 --> 195 <url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url> 196 </mirror> 197 </mirrors> 198 199 <!-- profiles 200 | This is a list of profiles which can be activated in a variety of ways, and which can modify 201 | the build process. Profiles provided in the settings.xml are intended to provide local machine- 202 | specific paths and repository locations which allow the build to work in the local environment. 203 | 204 | For example, if you have an integration testing plugin - like cactus - that needs to know where 205 | your Tomcat instance is installed, you can provide a variable here such that the variable is 206 | dereferenced during the build process to configure the cactus plugin. 207 | 208 | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles 209 | section of this document (settings.xml) - will be discussed later. Another way essentially 210 | relies on the detection of a system property, either matching a particular value for the property, 211 | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a 212 | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'. 213 | Finally, the list of active profiles can be specified directly from the command line. 214 | 215 | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact 216 | repositories, plugin repositories, and free-form properties to be used as configuration 217 | variables for plugins in the POM. 218 | 219 |--> 220 <profiles> 221 <!-- profile 222 | Specifies a set of introductions to the build process, to be activated using one or more of the 223 | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/> 224 | or the command line, profiles have to have an ID that is unique. 225 | 226 | An encouraged best practice for profile identification is to use a consistent naming convention 227 | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc. 228 | This will make it more intuitive to understand what the set of introduced profiles is attempting 229 | to accomplish, particularly when you only have a list of profile id's for debug. 230 | 231 | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo. 232 <profile> 233 <id>jdk-1.4</id> 234 235 <activation> 236 <jdk>1.4</jdk> 237 </activation> 238 239 <repositories> 240 <repository> 241 <id>jdk14</id> 242 <name>Repository for JDK 1.4 builds</name> 243 <url>http://www.myhost.com/maven/jdk14</url> 244 <layout>default</layout> 245 <snapshotPolicy>always</snapshotPolicy> 246 </repository> 247 </repositories> 248 </profile> 249 --> 250 251 <!-- 252 | Here is another profile, activated by the system property 'target-env' with a value of 'dev', 253 | which provides a specific path to the Tomcat instance. To use this, your plugin configuration 254 | might hypothetically look like: 255 | 256 | ... 257 | <plugin> 258 | <groupId>org.myco.myplugins</groupId> 259 | <artifactId>myplugin</artifactId> 260 | 261 | <configuration> 262 | <tomcatLocation>${tomcatPath}</tomcatLocation> 263 | </configuration> 264 | </plugin> 265 | ... 266 | 267 | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to 268 | anything, you could just leave off the <value/> inside the activation-property. 269 | 270 <profile> 271 <id>env-dev</id> 272 273 <activation> 274 <property> 275 <name>target-env</name> 276 <value>dev</value> 277 </property> 278 </activation> 279 280 <properties> 281 <tomcatPath>/path/to/tomcat/instance</tomcatPath> 282 </properties> 283 </profile> 284 --> 285 <profile> 286 <id>nexus</id> 287 <repositories> 288 <repository> 289 <id>central</id> 290 <url>http://central</url> 291 <releases> 292 <enabled>true</enabled> 293 </releases> 294 <snapshots> 295 <enabled>true</enabled> 296 </snapshots> 297 </repository> 298 </repositories> 299 300 <pluginRepositories> 301 <pluginRepository> 302 <id>central</id> 303 <url>http://central</url> 304 <releases> 305 <enabled>true</enabled> 306 </releases> 307 <snapshots> 308 <enabled>true</enabled> 309 </snapshots> 310 </pluginRepository> 311 </pluginRepositories> 312 </profile> 313 <profile> 314 <id>development</id> 315 <repositories> 316 <repository> 317 <id>central</id> 318 <url>http://central</url> 319 <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases> 320 <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots> 321 </repository> 322 </repositories> 323 <pluginRepositories> 324 <pluginRepository> 325 <id>central</id> 326 <url>http://central</url> 327 <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases> 328 <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots> 329 </pluginRepository> 330 </pluginRepositories> 331 </profile> 332 <profile> 333 <!--this profile will allow snapshots to be searched when activated--> 334 <id>public-snapshots</id> 335 <repositories> 336 <repository> 337 <id>public-snapshots</id> 338 <url>http://public-snapshots</url> 339 <releases><enabled>false</enabled></releases> 340 <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots> 341 </repository> 342 </repositories> 343 <pluginRepositories> 344 <pluginRepository> 345 <id>public-snapshots</id> 346 <url>http://public-snapshots</url> 347 <releases><enabled>false</enabled></releases> 348 <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots> 349 </pluginRepository> 350 </pluginRepositories> 351 </profile> 352 </profiles> 353 354 <!-- activeProfiles 355 | List of profiles that are active for all builds. 356 | 357 <activeProfiles> 358 <activeProfile>alwaysActiveProfile</activeProfile> 359 <activeProfile>anotherAlwaysActiveProfile</activeProfile> 360 </activeProfiles> 361 --> 362 <activeProfiles> 363 <activeProfile>nexus</activeProfile> 364 <activeProfile>development</activeProfile> 365 <activeProfile>public-snapshots</activeProfile> 366 </activeProfiles> 367 </settings>
6、pom.xml配置
在项目中的pom.xml文件如加入如下代码:
1 <distributionManagement> 2 <repository> 3 <id>nexus</id> 4 <name>Releases</name> 5 <url>http://localhost:8081/repository/maven-releases</url> 6 </repository> 7 <snapshotRepository> 8 <id>nexus</id> 9 <name>Snapshot</name> 10 <url>http://localhost:8081/repository/maven-snapshots</url> 11 </snapshotRepository> 12 </distributionManagement>
7、总结
从此以后,无论下载还是上传,我们的私服都会记录jar。并且放入私服仓库中,关于如何丰富自己的私服文件,我以后再写文章探讨。
参考网址:http://books.sonatype.com/nexus-book/3.3/reference/install.html#install-sect-downloading
http://blog.csdn.net/yamaxifeng_132/article/details/52479891
码字不易,尊重原创,转载请注明:https://www.cnblogs.com/adeng/p/7065717.html