私服是什么

私服,私有服务器,是公司内部Maven项目经常需要的东东,不总结一下,不足以体现出重视。Nexus是常用的私用Maven服务器,一般是公司内部使用。下载地址是http://www.sonatype.org/nexus/go,默认端口8081,这里我选择最新版nexus-2.5.0-04。

常用功能

Nexus常用功能就是:指定私服的中央地址、将自己的Maven项目指定到私服地址、从私服下载中央库的项目索引、从私服仓库下载依赖组件、将第三方项目jar上传到私服供其他项目组使用。
开启Nexus服务后访问url地址http://localhost:8081/nexus/(推荐使用自己的ip地址),之后登录系统,用户名密码分别是:admin/admin123.
最频繁的就是点击左侧菜单栏的Repositories按钮

一般用到的仓库种类是hosted、proxy。Hosted代表宿主仓库,用来发布一些第三方不允许的组件,比如Oracle驱动、比如商业软件jar包。Proxy代表代理远程的仓库,最典型的就是Maven官方中央仓库、JBoss仓库等等。如果构建的Maven项目本地仓库没有依赖包,那么就会去这个代理站点去下载,那么如果代理站点也没有此依赖包,就回去远程中央仓库下载依赖,这些中央仓库就是proxy。代理站点下载成功后再下载至本机。笔者认为,其实Maven这个自带的默认仓库一般情况下已经够大多数项目使用了。特殊情况时在配置新的仓库,指定url即可,一般熟悉ExtJS的人操作这个Nexus都没什么问题,单词不是很难,不明白的查查单词基本差不多。就是如果Sonatype公司对其做了国际化一的处理就更好了。

hosted 类型的仓库,内部项目的发布仓库
releases 内部的模块中release模块的发布仓库
snapshots 发布内部的SNAPSHOT模块的仓库
3rd party 第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去
proxy 类型的仓库,从远程中央仓库中寻找数据的仓库
group 类型的仓库,组仓库用来方便我们开发人员进行设置的仓库

maven项目索引

下载Maven项目索引,项目索引是为了使用者能够在私服站点查找依赖使用的功能

保存后后台会运行一个任务,点击菜单栏的Scheduled Tasks选项即可看到有个任务在RUNNING。 下载完成后,Maven索引就可以使用了,在搜索栏输入要搜索的项,就可以查到相关的信息。例如spring-core

就可以检索出它的相关信息,包括怎么配置依赖信息。我们要想使用这个私服仓库,先在项目pom中配置相关私服信息

指定仓库

1

2

3

4

5

6

7

8

9

10

11

12

13

<repositories>

    <repository>

        <id>nexus</id>

        <name>nexus</name>

        <url>http://192.168.1.103:8081/nexus/content/groups/public/</url>

        <releases>

            <enabled>true</enabled>

        </releases>

        <snapshots>

            <enabled>true</enabled>

        </snapshots>

    </repository>

</repositories>

这样只有本项目才在私服下载组件

这样这个Maven项目构建的时候会从私服下载相关依赖。当然这个配置仅仅是在此项目中生效,对于其他项目还是不起作用。如果相对Maven的其他项目也生效的话。需要修改全局的settings.xml文件。

修改settings.xml为

追加激活profile

1

2

3

<activeProfiles>

    <activeProfile>central</activeProfile>

</activeProfiles>

之后所有本机的Maven项目就在私服下载组件。(这样比较好)

项目的发布

1

2

3

4

5

6

7

8

9

10

11

12

<distributionManagement>

    <repository>

        <id>user-release</id>

        <name>User Project Release</name>

        <url>http://192.168.1.103:8081/nexus/content/repositories/releases/</url>

    </repository>

    <snapshotRepository>

        <id>user-snapshots</id>

        <name>User Project SNAPSHOTS</name>

        <url>http://192.168.1.103:8081/nexus/content/repositories/snapshots/</url>

    </snapshotRepository>

</distributionManagement>

注意配置了还是发布项目到私服失败,原因为没有权限

配置权限在settings.xml

然后运行发布
clean deploy
在控制台发布成功
然后进入到私服上的仓库中,看一下确实存在刚刚发布的项目

宿主库——3rd party

假如我们下载了Oracle的驱动程序jar包想给其他项目组使用,就需要上传该jar包。选中宿主库——3rd party,之后选择Artifact Upload上传至宿主空间。

最后点击上传

via:http://blog.csdn.net/shenshen123jun/article/details/9084293

Nexus3

作为一名工程师,在日常的学习和工作中,时常会遇到,项目工程中需要引用到其他的项目包,例如像需要引入第三方框架,或者是国外下载不下来的包。那么这个时候,就需要用到私服了,现在已经升级到Nexus3版本了,还有很多同学在用Nexus2,是时候该升升级了。还有一些同学,竟然还在直接加载本地包,或者一行行代码将别人的项目代码拷贝过来…….这样的方式都已经非常落后了。


一、具体的安装操作,在此不做累赘

推荐两篇博文:对照着操作一下就好了。

1、Linux搭建Nexus图文详解

2、将Nexus3作为你的仓库

二、有三点比较重要的地方

1、一定要按照上述步骤2配置仓库组

2、将仓库添加到仓库组中

三、配置Settings.xml文件

只有两个地方需要配置私服,已经用注释标示出来了,请参考。

<?xml version="1.0" encoding="UTF-8"?><!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
--><!--| This is the configuration file for Maven. It can be specified at two levels:||  1. User Level. This settings.xml file provides configuration for a single user,|                 and is normally provided in ${user.home}/.m2/settings.xml.||                 NOTE: This location can be overridden with the CLI option:||                 -s /path/to/user/settings.xml||  2. Global Level. This settings.xml file provides configuration for all Maven|                 users on a machine (assuming they're all using the same Maven|                 installation). It's normally provided in|                 ${maven.conf}/settings.xml.||                 NOTE: This location can be overridden with the CLI option:||                 -gs /path/to/global/settings.xml|| The sections in this sample file are intended to give you a running start at| getting the most out of your Maven installation. Where appropriate, the default| values (values used when the setting is not specified) are provided.||-->
<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| The path to the local repository maven will use to store artifacts.|| Default: ${user.home}/.m2/repository<localRepository>/path/to/local/repo</localRepository>--><!-- interactiveMode| This will determine whether maven prompts you when it needs input. If set to false,| maven will use a sensible default value, perhaps based on some other setting, for| the parameter in question.|| Default: true<interactiveMode>true</interactiveMode>--><!-- offline| Determines whether maven should attempt to connect to the network when executing a build.| This will have an effect on artifact downloads, artifact deployment, and others.|| Default: false<offline>false</offline>--><!-- pluginGroups| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.|--><pluginGroups><!-- pluginGroup| Specifies a further group identifier to use for plugin lookup.<pluginGroup>com.your.plugins</pluginGroup>--></pluginGroups><!-- proxies| This is a list of proxies which can be used on this machine to connect to the network.| Unless otherwise specified (by system property or command-line switch), the first proxy| specification in this list marked as active will be used.|--><proxies><!-- proxy| Specification for one proxy, to be used in connecting to the network.|<proxy><id>optional</id><active>true</active><protocol>http</protocol><username>proxyuser</username><password>proxypass</password><host>proxy.host.net</host><port>80</port><nonProxyHosts>local.net|some.host.com</nonProxyHosts></proxy>--></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| Specifies the authentication information to use when connecting to a particular server, identified by| a unique name within the system (referred to by the 'id' attribute below).|| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are|       used together.|<server><id>deploymentRepo</id><username>repouser</username><password>repopwd</password></server>--><!-- Another sample, using keys to authenticate.<server><id>siteServer</id><privateKey>/path/to/private/key</privateKey><passphrase>optional; leave empty if not used.</passphrase></server>--><!--配置私服--><server><id>nexus-snapshots</id><username>admin</username><password>admin123</password></server><server><id>nexus-releases</id><username>admin</username><password>admin123</password></server></servers><!-- mirrors| This is a list of mirrors to be used in downloading artifacts from remote repositories.|| It works like this: a POM may declare a repository to use in resolving certain artifacts.| However, this repository may have problems with heavy traffic at times, so people have mirrored| it to several places.|| That repository definition will have a unique id, so we can create a mirror reference for that| repository, to be used as an alternate download site. The mirror site will be the preferred| server for that repository.|--><mirrors><!-- mirror| Specifies a repository mirror site to use instead of a given repository. The repository that| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.|<mirror><id>mirrorId</id><mirrorOf>repositoryId</mirrorOf><name>Human Readable Name for this Mirror.</name><url>http://my.repository.com/repo/path</url></mirror>--><!--配置私服--><mirror><id>central</id><name>central</name><url>http://192.168.xx.xxx:8081/repository/maven-group/</url><mirrorOf>*</mirrorOf></mirror></mirrors><!-- profiles| This is a list of profiles which can be activated in a variety of ways, and which can modify| the build process. Profiles provided in the settings.xml are intended to provide local machine-| specific paths and repository locations which allow the build to work in the local environment.|| For example, if you have an integration testing plugin - like cactus - that needs to know where| your Tomcat instance is installed, you can provide a variable here such that the variable is| dereferenced during the build process to configure the cactus plugin.|| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles| section of this document (settings.xml) - will be discussed later. Another way essentially| relies on the detection of a system property, either matching a particular value for the property,| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.| Finally, the list of active profiles can be specified directly from the command line.|| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact|       repositories, plugin repositories, and free-form properties to be used as configuration|       variables for plugins in the POM.||--><profiles><!-- profile| Specifies a set of introductions to the build process, to be activated using one or more of the| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>| or the command line, profiles have to have an ID that is unique.|| An encouraged best practice for profile identification is to use a consistent naming convention| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.| This will make it more intuitive to understand what the set of introduced profiles is attempting| to accomplish, particularly when you only have a list of profile id's for debug.|| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.<profile><id>jdk-1.4</id><activation><jdk>1.4</jdk></activation><repositories><repository><id>jdk14</id><name>Repository for JDK 1.4 builds</name><url>http://www.myhost.com/maven/jdk14</url><layout>default</layout><snapshotPolicy>always</snapshotPolicy></repository></repositories></profile>--><!--| Here is another profile, activated by the system property 'target-env' with a value of 'dev',| which provides a specific path to the Tomcat instance. To use this, your plugin configuration| might hypothetically look like:|| ...| <plugin>|   <groupId>org.myco.myplugins</groupId>|   <artifactId>myplugin</artifactId>||   <configuration>|     <tomcatLocation>${tomcatPath}</tomcatLocation>|   </configuration>| </plugin>| ...|| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to|       anything, you could just leave off the <value/> inside the activation-property.|<profile><id>env-dev</id><activation><property><name>target-env</name><value>dev</value></property></activation><properties><tomcatPath>/path/to/tomcat/instance</tomcatPath></properties></profile>--></profiles><!-- activeProfiles| List of profiles that are active for all builds.|<activeProfiles><activeProfile>alwaysActiveProfile</activeProfile><activeProfile>anotherAlwaysActiveProfile</activeProfile></activeProfiles>-->
</settings>

上述配置完成后,就可以愉快的使用了。

使用nexus搭建maven私服教程详解相关推荐

  1. 使用Nexus搭建Maven私服教程(附:nexus上传、下载教程)

    一.基本介绍(Nexus(maven私服)) 1,如果没有搭建私服会有什么问题? 如果没有私服,我们所需的所有构件都需要通过 Maven 的中央仓库或者第三方的 Maven 仓库下载到本地,而一个团队 ...

  2. Maven学习总结(九)——使用Nexus搭建Maven私服

    2019独角兽企业重金招聘Python工程师标准>>> Maven学习总结(九)--使用Nexus搭建Maven私服 一.搭建nexus私服的目的 为什么要搭建nexus私服,原因很 ...

  3. 如何使用Nexus搭建Maven私服

    如何使用Nexus搭建Maven私服 转载于:https://www.cnblogs.com/valuestack/p/nexus-and-maven.html

  4. 用nexus搭建maven私服(整合网上文章而成的)

    背景:最近项目准备使用maven+nexus来管理构件,也方便项目的构建,所以老大就让俺研究研究怎么用nexus搭建maven私服 环境:win7-64.nexus-2.2.maven-3.0.4.j ...

  5. 使用Nexus搭建Maven私服、私服下载与上传

    目录 一.概念 1.私服简介 2.私服的好处 3.搭建私服的开源仓库管理软件 二.使用Nexus搭建Maven私服(Windows环境) 1.安装jdk 2.下载即安装Nexus 2.1 下载 2.2 ...

  6. Sonatype Nexus搭建maven私服仓库

    搭建Maven私服仓库 1. 概述 Sonatype Nexus是一种特殊的远程仓库,是架设在局域网内的仓库管理器. nexus 可以搭建局域网maven私服仓库(实现局域网用户共享),并且支持代理广 ...

  7. linux设置nexus开机自启动_在linux中使用nexus搭建maven私服

    首先介绍下为什么要搭建maven私服,简单点说就是就是把项目工程中的Jar包放在一个服务器上,每次Jar包的修改都能去私服上面Down到本地.可以对整个项目组的人形成一个统一的管理. 2.下载完之后就 ...

  8. Linux下使用Nexus搭建Maven私服

    Nexus是一个强大的Maven仓库管理器,它极大地简化了自己内部仓库的维护和外部仓库的访问.利用Nexus你可以只在一个地方就能够完全控制访问和部署在你所维护仓库中的每个Artifact.Nexus ...

  9. Windows 下Nexus搭建Maven私服

    1. 为什么使用Nexus 如果没有私服,我们所需的所有构件都需要通过maven的中央仓库和第三方的Maven仓库下载到本地,而一个团队中的所有人都重复的从maven仓库下载构件无疑加大了仓库的负载和 ...

最新文章

  1. c 判断文件是否存在_C语言编程之怎样判断某一文件是否存在
  2. Windows 7 Natvie VHD
  3. Java工程中使用Log4j小记
  4. hadoop的关键进程
  5. 与 OpenCV 1 同时使用
  6. mysql提高吞吐量_垃圾收集:提高吞吐量
  7. 大数据平台构建_如何像产品一样构建数据平台
  8. Java通过cal.get(Calendar.MONTH)比真实月份少一个月
  9. PreSubclassWindow()作用
  10. Node.js入门(含NVM、NPM、NVM的安装)-(转载)
  11. 计算机一级安装的软件要钱吗,电脑没装这5个软件,基本算是废了
  12. 台北 ModernWeb.tw 参会流水账以及感想
  13. 千锋培训python好吗?靠谱吗?
  14. (DFS)深度优先搜索算法详解
  15. 微信卡券怎么制作以及卡券封号推送消息技术分享
  16. 玩机搞机----mtk芯片机型 另类制作备份线刷包的方式 读写分区等等
  17. matlab 空间曲面的绘制
  18. C++内存问题(很多公司面试的题目,值得一看,看懂了别忘了告诉我)
  19. 将敏捷应用于工业机械开发
  20. 408总线的串并行分类及系统总线局部总线分类

热门文章

  1. [已解决] EnvironmentLocationNotFound: Not a conda environment: C:\Program Files\Anaconda3
  2. VERTU广告登陆央视:情怀与创新的恪守之道
  3. 栈(stack)——什么是栈?
  4. 45特征03——最小多项式的概念和性质、广义特征子空间分解
  5. python写xml多了ns0_python – SUDS生成的XML不正确
  6. 易语言写64位魔兽世界游戏 寻路call 教程
  7. Python爬取国家数据中心环境数据(全国城市空气质量小时报)并导入csv文件
  8. 3369. 三千米健身步道
  9. 如何在win10新建菜单添加新的文件类型
  10. 应用统计学与R语言实现学习笔记(三)——描述性统计