文档章节

maven使用nexus3.3在windows下搭建私服

HiAscend
 HiAscend
发布于 2017/07/05 20:39
字数 2691
阅读 28
收藏 0
点赞 0
评论 0

1. 私服简介

私服是指私有服务器,是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构建。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载。

2. nexus3的环境安装

下载地址:https://www.sonatype.com/download-oss-sonatype

解压后如下:

3. nexus3的启动

配置完成后,打开cmd或者powershell,进入nexus-3.0.1-01\bin下。

执行:nexus.exe /run

注意斜杠

最后经过一大轮的日志打印,最后出现如下界面,说明nexus私服已经搭建好了

启动成功后,默认用户名admin 密码:admin123

配置路径:D:\server\nexus-3.3.2-02-win64\sonatype-work\nexus3\db\security\user.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\nexus-3.3.2-02-win64\nexus-3.3.2-02\etc\nexus-default.properties   之类的,若在:D:\server\nexus-3.3.2-02-win64\sonatype-work\nexus3\etc\nexus.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:\Users\Administrator\.m2\settings.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

本文转载自:http://www.cnblogs.com/adeng/p/7065717.html

共有 人打赏支持
HiAscend
粉丝 0
博文 24
码字总数 923
作品 0
东城
程序员
Maven学习 使用Nexus搭建Maven私服

为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给项目组人员,因此就不能使用maven访问远程的仓库地址,所以很有必要在局域网里找一台有外网权限的机器,搭建nexus私服,然后开发...

coder_life ⋅ 2016/08/12 ⋅ 0

nexus索引同步不了的解决方法

由于网络经常抽风,maven经常卡死。所以在本地搭建了个nexus私服。搭建私服后发现索引不能完整地同步,整合网络信息,解决方案如下: 1、通过x度云离线下载等方式下载如下两个文件:(如果r...

无争 ⋅ 2015/01/29 ⋅ 1

使用nexus搭建Maven私服

为什么要用远程仓库(私服)? 使用maven的好处就是可以对项目的各种依赖进行统一管理,在pom文件中定以好依赖,就可以从maven中央库或者第三方库中下载到本地。但在企业内部使用也会遇到一些...

沉淀人生 ⋅ 04/11 ⋅ 0

Maven 系列 五 :使用Nexus搭建Maven私服

1 . 私服简介   私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则...

lyg945 ⋅ 2014/06/23 ⋅ 4

Linux 下使用 Nexus

为什么要搭建私服? 在开发过程中,有时候会使用到公司内部的一些开发包,显然把这些包放在外部是不合适的。另外,由于项目一直在开发中,这些内部的依赖可能也在不断的更新。可以通过搭建公...

devin223 ⋅ 2017/06/05 ⋅ 0

Linux下使用nexus搭建maven仓库私服

有个maven私服可以很方便地管理我们的jar包和发布构建到远程仓库,本文就介绍了如何在linux下一步步使用nexus搭建maven私服 原文链接: http://www.tuicool.com/articles/E7ZBv2 下载安装 最...

宁宁爸 ⋅ 2015/09/17 ⋅ 0

MAVEN私服搭建

Maven私服搭建 1:启动nexus服务报错 搭建指南参考:http://wenku.baidu.com/view/8b709265caaedd3383c4d3f8.html 查看启动日志:D:soft-hwnexus-2.6.3-01-bundlenexus-2.6.3-01logs Waiting ......

angie_hawk7 ⋅ 2014/05/07 ⋅ 1

使用maven,搭建nexus私服

maven的中央仓库特别的慢,近期为了推进项目转为maven的结构,必须提高下载的速度,摸索着搭建一个私服。将过程记录在此。 一直使用IDEA的maven的插件,并没有在系统中安装maven 1、先安装m...

雷斯林 ⋅ 2016/11/26 ⋅ 0

阿里云本地开发环境搭建

阿里云本地开发环境搭建 一、edas中心搭建 1.准备工作: · 安装aliTomcat,下载Pandora 容器,参考:https://help.aliyun.com/documentdetail/44158.html?spm=5176.doc44158.6.626.rNC8kS ...

老金斯基 ⋅ 2017/12/22 ⋅ 0

Nexus搭建两种方式

Nexus私服安装 第一步:下载nexus.war包,然后拷贝到tomcat下的webapps目录中 第二步:启动tomcat 第三步:访问http://localhost:8080/nexus-2.7.0-06/index.html#welcome显示如下: 第四步:...

PunkSPIDER ⋅ 2017/07/10 ⋅ 0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

CENTOS7防火墙命令记录

安装Firewall命令: yum install firewalld firewalld-config Firewall开启常见端口命令: firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --zone=public --add-po......

cavion ⋅ 43分钟前 ⋅ 0

【C++】【STL】利用chromo来测量程序运行时间与日志时间打印精确到微秒

直接上代码吧,没啥好说的。头疼。 #include <iostream>#include <string>#include <ctime>#include <sstream>#include <iomanip>#include <thread>#include <chrono>using ......

muqiusangyang ⋅ 46分钟前 ⋅ 0

Mac环境下svn的使用

在Windows环境中,我们一般使用TortoiseSVN来搭建svn环境。在Mac环境下,由于Mac自带了svn的服务器端和客户端功能,所以我们可以在不装任何第三方软件的前提下使用svn功能,不过还需做一下简...

故久呵呵 ⋅ 56分钟前 ⋅ 0

破解公司回应苹果“USB限制模式”:已攻破

本周四,苹果发表声明称 iOS 中加入了一项名为“USB 限制模式”的功能,可以防止 iPhone 在连接其他设备的时候被破解,并且强调这一功能并不是针对 FBI 等执法部门,为的是保护用户数据安全。...

六库科技 ⋅ 57分钟前 ⋅ 0

MyBtais整合Spring Boot整合,TypeHandler对枚举类(enum)处理

概要 问题描述 我想用枚举类来表示用户当前状态,枚举类由 code 和 msg 组成,但我只想把 code 保存到数据库,查询处理,能知道用户当前状态,这应该怎么做呢?在 Spring 整合MyBatis 的时候...

Wenyi_Feng ⋅ 今天 ⋅ 0

synchronized与Lock的区别

# <center>王梦龙的读书笔记第一篇</center> ## <center>-synchronized与Lock的区别</centre> ###一、从使用场景来说 + synchronized 是能够注释代码块、类、方法但是它的加锁是和解锁使用一......

我不想加班 ⋅ 今天 ⋅ 0

VConsole的使用

手机端控制台打印输出,方便bug的排查。 首先需要引入vconsole.min.js 文件,然后在文件中创造实例。就能直接使用了。 var vConsole = new VConsole(); vConsole的文件地址...

大美琴 ⋅ 今天 ⋅ 0

Java NIO之字符集

1 字符集和编解码的概念 首先,解释一下什么是字符集。顾名思义,就是字符的集合。它的初衷是把现实世界的符号映射为计算机可以理解的字节。比如我创造一个字符集,叫做sex字符集,就包含两个...

士别三日 ⋅ 今天 ⋅ 0

Spring Bean基础

1、Bean之间引用 <!--如果Bean配置在同一个XML文件中,使用local引用--><ref bean="someBean"/><!--如果Bean配置在不同的XML文件中,使用ref引用--><ref local="someBean"/> 其实两种......

霍淇滨 ⋅ 今天 ⋅ 0

05、基于Consul+Upsync+Nginx实现动态负载均衡

1、Consul环境搭建 下载consul_0.7.5_linux_amd64.zip到/usr/local/src目录 cd /usr/local/srcwget https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_linux_amd64.zip 解压consu......

北岩 ⋅ 今天 ⋅ 0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部