Maven配置Nexus私服

官方文档http://books.sonatype.com/nexus-book/3.0/reference/maven.html#maven-sect-single-group

1,下载安装

首先你需要下载apache maven。官方地址:https://maven.apache.org/download.cgi

这里介绍的是windows环境中的配置。
2,修改配置文件

解压后,备份 apache-maven-3.3.9\conf\settings.xml 文件。

用如下文件内容替换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 at

    http://www.apache.org/licenses/LICENSE-2.0

Unless 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.home}/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>
    Nexus Repository Manager 3.0私服账号密码,依据服务修改
    -->
    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</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>
    -->
  </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>
      <!--This sends everything else to /public 私服公共仓库地址-->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://192.168.13.169:8081/repository/maven-public/</url>
    </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>
    -->
    <profile>
      <id>jdk-1.8</id>

      <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.8</jdk>
      </activation>
    </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>
    -->
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://192.168.13.169:8081/repository/maven-public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://192.168.13.169:8081/repository/maven-public/</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
  <activeProfiles>
    <!--make the profile active all the time 激活-->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

3,部署配置

修改maven工程的pom.xml文件,添加如下内容(其中的IP及端口号替换为对应的nexus私服,id就是在settings.xml中对应的服务id):

<distributionManagement>
    <repository>
      <id>nexus</id>
      <name>Releases</name>
      <url>http://192.168.13.169:8081/repository/maven-releases</url>
    </repository>
    <snapshotRepository>
      <id>nexus</id>
      <name>Snapshot</name>
      <url>http://192.168.13.169:8081/repository/maven-snapshots</url>
    </snapshotRepository>
</distributionManagement>
时间: 2024-10-03 16:59:31

Maven配置Nexus私服的相关文章

Maven之——Nexus私服

Maven之--Nexus私服 1.    Nexus简介 2005年12月.TamasCservernak由于受不了匈牙利电信ADSL的低速度.开始着手开发Proximily.可以代理并缓存Maven构件.2007被Sonatype邀请参与创建一个Maven仓库管理软件.这就是后来的Nexus.牛人总是在不经意间显露着他们的能力与才华. Nexus有开源版和专业版.专业版收费.下面的都是建立在开源版的Nexus. 2.    Nexus安装 Nexus本身是典型的JavaWeb应用.ExtJS

maven搭建nexus私服在myeclipse中的使用

开始注明:下方的内容中个别图片是从几个网站中黏贴进来的,时间太长忘记注明来源了,原作者看见能提醒我下,我注明,抱歉!下方大多数是自己总结的,有些描述的比较细,只是论述了个人能理解的部分.如果不知道maven如果在myeclipse中配置,那么请看我上篇博文:"maven在myeclipse8.6中的配置". 1.简介 这里主要是对maven和nexus私服的使用.nexus私服,可以理解为在本地局域网建立了一个类似中央仓库的处理器,我们开始将资料下载到中央服务器中,然后在本地maven

Maven使用Nexus私服的配置

工作记录 —————————————————————————————— 配置文件 apache-maven-3.3.3\conf\settings.xml 在mirrors(镜像)之间配置. url为私服地址 <!-- 配置maven只使用私服时,第一个mirrorOf之间写*就行.osgeo和geosolutions不能使用nexus,必须绕过--> <mirror> <id>nexus</id> <mirrorOf>external:*,!o

【Maven】---Nexus私服配置Setting和Pom

maven---nexus私服配置setting和pom 上一遍博客已经在linux服务器上,搭建好nexus私服了,博客地址:Linux搭建Nexus3.X私服 现在就需要配置setting.xml和pom.xml来使nexus作为maven的私服.setting.xml文件在conf下面,pom.xml是在你创建maven项目中的pom.xml中. 一.将jar发送到nexus私服务器 1.创建maven项目 创建一个最简单的maven项目,然后新建一个工具类,用来测试当把它打成jar包放到

Maven基础配置--nexus私服配置

登录nexus私服后台,按照下图1-3的顺序进行添加仓库: 其中步骤3有三种仓库类型(Type)进行选择 1. Hosted Repository:本地仓库,在私服服务器上存放用户自行上传的jar包: 2. Proxy Repository:远程代理仓库,从远程下载jar包,并保存在私服服务器: 3. Repository Group:可把上述仓库合并为一个组,方便使用: 两种jar包类型(Policy) 1. Release:稳定发布的版本: 2. Snapshot:不稳定的,正在开发中的版本

Unbuta环境下配置Nexus私服仓库

Nexus私服是用来管理gradle和maven包的仓库 私服,私有服务器,私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件.有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库:否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载 ubuntu基于linux的免费开源桌面PC操作系统,十分契合英特尔的超极本定位,支持x86.64位和ppc架构. 由于公司服务器是基于Ubunta系统的,所以要在该系统下搭建Nexus仓库

部署Maven与Nexus(私服)

博文大纲:一.Maven简介1)Maven的功能:2)Maven使用场景(从运维人员的角度来看):3)Maven仓库二.部署Maven1)配置jdk环境2)部署Maven三.部署Nexus私服1)Nexus简介2)部署Nexus四.Maven配置nexus私服,将远程仓库设置成本地搭建的Nexus私服1)修改maven的主配置文件2)创建一个maven项目进行测试3)配置认证,将打包好的项目上传到nexus中4)上传到maven-release仓库5)上传第三方maven 一.Maven简介 M

Maven、eclipse与Nexus私服配置指南

1.1  Maven 1.1.1  相关概念 Maven是一个软件项目管理工具,通过它可便捷的管理项目的生命周期.即项目的jar包依赖,开发,测试,发布打包.版本等.虽然目前的IDE工具(如eclipse)可管理开发.发布.打包工作,但还没有形成一套完成的体系. Maven有以下几个功能特点: 1. jar包依赖 这个也许会maven最突出的特点.使用maven进行开发时,不需要上网单独下载jar包,只需要在配置文件pom.xml中配置jar包的依赖关系,就可以自动下载jar包到我们的项目中(在

Maven创建并管理Web项目(上传Web项目的API的JAR到Nexus 私服上)

目录 1.简介 2.安装Eclipse Maven插件 3.用Eclipse创建Maven Web项目 4.配置settings.xml 文件并下载项目依赖的JAR,并上传Web项目的api的JAR到Nexus 私服 1.简介 Maven.Nexus 私服的安装和配置和Maven的优点在Maven和 Sonatype Nexus私服的安装.配置及使用入门已经有介绍了,这里就不在介绍了,今天我们要介绍Maven创建并管理Web项目,方便我们项目的开发和管理. 2.安装Eclipse Maven插件