Maven系列(一):安装、配置Settings.xml配置文件与使用

2023-11-11

安装与使用


今天博主将为大家分享一下Maven的下载与安装,不喜勿喷,如有异议欢迎讨论!

以下所写内容均与以前的文章有联系可以前往博文查看,陈永佳的博客


Maven

前言

首先,Maven是基于项目对象模型(POM project object model),可以通过一小段描述信息(配置)来管理项目的构建,报告和文档的软件项目管理工具[百度百科]

这种又是大白话,如果没明白maven是什么,那么上面这句话跟没说一样,Maven的核心功能便是合理叙述项目间的依赖关系,就是通过pom.xml文件的配置管理和获取jar包,而不用手动去添加jar包,而这里pom.xml文件对于学了一点maven的人来说,就有些熟悉了,如果需要使用pom.xml来获取jar包,那么首先该项目就必须为maven项目,就是在java项目和web项目的上面包裹了一层maven,本质上java项目还是java项目,web项目还是web项目,但是包裹了maven之后,就可以使用maven提供的一些功能了(通过pom.xml添加jar包)。


下载安装

打开浏览器,在地址栏输入:http://maven.apache.org/download.cgi 进入Maven官网,按照如下图所示将Maven下载到本地,无需解压:
在这里插入图片描述下载完成后点击打开文件夹,点击conf开始配置Maven的Settings.xml文件(用于配置,从远程镜像下载到本地的jar存放位置,以及远程镜像仓库的地址):
在这里插入图片描述在这里插入图片描述下面可以复制我的配置信息使用:

下文请注意我在复制内容信息里的注释,分别写了从远程镜像下载的jar的存放文件夹和路径即本地仓库,以及远程镜像配置(可以根据公司和企业的需要更改配置信息)

<?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>
  -->
  <!-- 在这里我们可以配置,下载后的jar存放的文件夹和路径,请自行更改存放路径 -->
	<localRepository>D:\apache-maven-3.3.9\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>
    -->
    <!-- nexus私库配置默认 -->
	<server>
      <id>thirdparty</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>central</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://central.maven.org/maven2/</url>
    </mirror>
<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>alimaven</id>
		<name>aliyun maven</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
		<mirrorOf>central</mirrorOf>
	</mirror>
	<mirror>
	-->
	
	<!-- 这里使用的是阿里的远程maven镜像,目前国内大多数都使用它 -->
	<mirror>
		 <id>alimaven</id>
		<name>aliyun maven</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
		<mirrorOf>central</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>
    -->
	<profile>
		<id>jdk-1.8</id>  
		<activation>  
			<activeByDefault>true</activeByDefault>  
			<jdk>1.8</jdk>  
		</activation>  
		<properties>  
			<maven.compiler.source>1.8</maven.compiler.source>  
			<maven.compiler.target>1.8</maven.compiler.target>  
			<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>  
		</properties>
	</profile>
  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

到这里Maven变配置完毕了,下一篇将为大家讲解配置好后的Maven如何配置到STS或eclipse中!


最后

  • 更多参考精彩博文请看这里:陈永佳的博客

  • 喜欢博主的小伙伴可以加个关注、点个赞哦,持续更新嘿嘿!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Maven系列(一):安装、配置Settings.xml配置文件与使用 的相关文章

  • 如何在 Grails 2.4 中外部化 Maven 凭证

    我正在尝试在 Grails 2 4 项目中从使用 Ivy 迁移到使用 Aether 解析器 我遇到的问题与外部化凭证有关 与此相关的信息可以在 Grails 手册中找到 http grails org doc latest guide co
  • 使用 Nginx 时缺少 HTTP 状态代码名称

    我正在使用 Nginx 将所有 HTTP 请求重定向到 HTTPS 在我的 Spring Boot 应用程序中 这是我正在使用的 nginx 配置 通过它我可以将所有请求重定向到 Https 但是当我这样做时 我得到了状态码返回正确 但没有
  • maven 3:访问​​“root”企业 POM 版本

    使用 Maven 3 0 4 我的任务是为我们的组织提供企业父级 POM 我的团队将为开发人员在使用此 POM 时遇到的疑问或问题提供支持 他们通常会将构建日志附加到支持票证中 因此 我希望我的公司 POM 将公司父级的版本回显到任何构建的
  • 实体创建无用的 id 字段

    我有一个CrudRepository与两个实体 Problem 特征实体总是创建一个附加的id数据库中的字段但未选择正确的characteristic id要生成的字段JSON machine entity machine id name
  • 如何从 jenkins 的现有项目生成 .hpi 插件

    我正在尝试使用 jenkins 的性能插件 但最新版本存在一些问题 如链接中所述 https issues jenkins ci org browse JENKINS 27100 https issues jenkins ci org br
  • Jackson 的 ObjectMapper 和 SQL 中的 RowMapper

    我们正在使用对象映射器 当将 ObjectMapper 与 RowMapper 一起使用时 是否应该在每个 mapRow 内部 如下所示 声明它 还是在 mapRow 外部声明为类公共成员 我认为根据本文 它应该作为公共类成员在外部 我应该
  • Maven Surefire:附加到 argLine

    我有 2 个配置文件 可能会也可能不会一起使用来运行一组测试 它们各自需要不同的 vmargs 来运行 但如果它们一起使用 则可以将它们相互附加 我正在寻找一种将 argLine 设置为其当前值加上我设置的值的串联的方法 我希望它会像这样简
  • JBehave 和 Maven - 如何跳过场景测试

    我正在使用 jbehave 和 jbehave maven 插件来运行一组场景测试 让我的测试类扩展 JUnitStories 一切都运行良好 唯一的问题是 我无法停止运行测试 每次我运行 Maven 安装目标时 它都会运行测试 我尝试在下
  • 使用 Spring boot 测试执行集成测试时无法注入自定义过滤器

    我在 spring 控制器中有 POST 方法 并且我正在尝试使用 Test Rest 模板交换在控制器上运行测试方法 控制器 java RequestMapping path rest projects RestController pu
  • 使用 Maven 构建 JavaFX 8

    我测试了使用 Netbeans 7 4 创建 JavaFX 8 项目 但不幸的是没有运气 这是 POM 文件
  • ClassNotFoundException:在嵌入了 cxf 依赖项的 OSGi 包中找不到 org.glassfish.jersey.internal.RuntimeDelegateImpl

    这与jax rs 2 0 更改默认实现 https stackoverflow com questions 17366266 jax rs 2 0 change default implementation我有一个 OSGi 包 其中包含
  • 在 Spring Context 加载实际的 Spring Bean 之前是否模拟了模拟 bean (@MockBean)?

    让我们以下面的例子为例 Autowired MockBean private Foo foobar Spring Context 是否加载类Foo首先 然后应用模拟 或者是 Mockbean以某种方式被检测到 Spring 创建并应用模拟而
  • Spring Boot MSSQL Kerberos 身份验证

    目前在我的春季靴子中application properties文件中 我指定以下行来连接到 MSSql 服务器 spring datasource url jdbc sqlserver localhost databaseName spr
  • OutputCapture 进行多次测试

    我正在使用 org springframework boot test OutputCapture 来测试记录某些内容的注释 它对于单个测试非常有效 当单独运行测试时 如果源文件中存在使用输出捕获的多个测试 但是当多个测试一起运行时 只有第
  • maven 无法下载 jacoco 0.7.10-SNAPSHOT jar

    我对此感到困惑 我的 pom xml 中有这个
  • 如何防止嵌入式netty服务器使用spring-boot-starter-webflux启动?

    我想使用 Springs 新的反应式在客户端和服务器应用程序之间建立通信webflux扩大 对于依赖管理我使用gradle 我在服务器和客户端上的 build gradle 文件基本上是 buildscript repositories m
  • 在 th:href 链接中使用模型属性

    有没有办法在 th href 链接中引用模型属性 例如 a a Here 当前用户是控制器中指定的模型变量 这可以很容易地访问 如th text标签 但是 那th href百里香解析失败 如果有任何方法以这种方式引用模型属性 则在th hr
  • spring boot框架下如何过滤tomcat产生的访问日志

    我们使用spring boot框架 通过嵌入式tomcat生成访问日志 访问日志的格式如下 server tomcat access log enabled true server tomcat access log pattern h l
  • 如何根据服务器/环境动态加载服务器配置?

    目前 我设置了 Maven 配置文件 以便能够为不同的环境 开发 演示 暂存 生产等 部署我的项目 并且它工作得很好 但问题是 对于我拥有的每个模块 Web 应用程序 我需要复制 粘贴此配置文件 它们都是属性文件 当我需要更改环境 服务器配
  • Maven 备用 pom

    调用 Maven 构建来指定替代文件来代替标准 pom xml 文件名时是否有参数 基本上 我需要运行test我的 Maven 构建目标是使用各种配置 现在我必须使用外部脚本来使用此配置更新标准 pom 然后恢复文件 我宁愿能够维护几个单独

随机推荐

  • 爬取新浪股票财务数据

    coding utf 8 import HTMLParser import urllib2 import sys type sys getfilesystemencoding 截止日期 每股净资产 每股收益 每股现金含量 每股资本公积金 固
  • ORACLE数据块

    下午在学习oracle 10g r2 concepts 在这留一笔 Oracle对数据库数据文件 datafile 中的存储空间进行管理的单位是数据块 data block 数据块是数据库中最小的 逻辑 数据单位 与数据块对应的 所有数据在
  • windows 10下vue 2.x 环境安装(npm网络环境不好时)

    windows 10下vue 环境安装 项目建立和运行 文章目录 windows 10下vue 环境安装 项目建立和运行 确定nodejs和npm已经安装 安装cnpm 安装vue 建立vue项目 使用vscode打开项目cnpm安装依赖
  • 一、OSI参考模型

    一 OSI参考模型 OSI Open System Interconnect 即开放式系统互连 一般都叫OSI参考模型 是ISO组织在1985年研究的网络互连模型 该体系结构标准定义了网络互连的七层框架 物理层 数据链路层 网络层 传输层
  • VMWare虚拟机文件夹共享不生效解决方法

    VMWare虚拟机文件夹共享不生效解决方法 mnt hgfs 中找不到共享文件夹 在安装了 vm tools 或 网上各种教程 vmhgfs fuse 都挂载不上可采取以下临时解决方法 1 关闭VMWare中的文件夹共享 2 重启虚拟机 3
  • nginx中健康检查(health_check)机制深入分析

    转自 https segmentfault com a 1190000002446630 很多人都知道nginx可以做反向代理和负载均衡 但是关于nginx的健康检查 health check 机制了解的不多 其实社区版nginx提供的he
  • 合宙Air724UG LuatOS-Air LVGL API控件--图表 (Chart)

    图表 Chart 一幅图胜过一千个字 通过图表展示出的数据内容能让用户更快速有效的了解数据特征 代码示例 创建图表 chart lvgl chart create lvgl scr act nil lvgl obj set size cha
  • 从零开始做单相逆变电源(硬件)

    文章目录 前言 一 主要模块需求 1 全桥模块 2 采样电路 光耦 前言 题目 单相正弦逆变电源 具体软件部分请参照从零开始做单相逆变电源 软件 一 主要模块需求 本系统以TM4C123GH6PM单片机 FPGA为控制核心 基于正弦脉冲宽度
  • 1654. 到家的最少跳跃次数

    文章目录 Tag 题目来源 题目解读 解题思路 实现细节 实现代码 复杂度分析 写在最后 Tag 广搜 上限证明 图论 题目来源 1654 到家的最少跳跃次数 题目解读 找到从位置 0 跳跃到位置 x 的最小跳跃次数 跳跃规则如下 前进方向
  • daytime协议的服务器和客户端程序,用Socket套接字实现DAYTIME协议的服务器和客户端程序-20210414073352.docx-原创力文档...

    用Socket套接字实现 DAY TIME 协议的服务器和客户端程序 一 设计目的 为了提高同学的自主动手能力 把理论知识运用于实 践中 从实践中更好的领悟所学的知识 二 题目要求及需求分析 网络I O程序设计 用Socket套接字实现DA
  • void指针的用法

    指针有两个属性 指向变量 对象的地址和长度 但是指针只存储地址 长度则取决于指针的类型 编译器根据指针的类型从指针指向的地址向后寻址 指针类型不同则寻址范围也不同 比如 int 从指定地址向后寻找4字节作为变量的存储单元 double 从指
  • quillEditor富文本编辑器实现插入视频

    quillEditor富文本编辑器实现插入视频 quillEditor富文本编辑器实现插入视频默认是通过iframe来展示的 并不符合我们的实际需求 我们需要直接展示视频 这里就是直接展示视频的效果 新建一个video模块用来替换原来vid
  • 云服务器选什么系统

    特网科技是一家领云计算服务提供商 拥有全球性服务 覆盖了超过200个国家和地区 提供多种不同的服务器操作系统 包括常见的Linux和Windows 以及一些非常特殊的OS 如FreeBSD和OpenSUSE 如何选择合适的操作系统对于服务器
  • MySQL安装教程(CentOS7系统)

    MySQL安装教程 1 使用wget指令下载MySQL安装包 指令 wget https dev mysql com get mysql57 community release el7 9 noarch rpm 效果展示 2 使用rpm指令
  • 371 .两整数之和

    371 两整数之和 地址 https leetcode cn com problems sum of two integers 题目 不使用运算符 和 计算两整数 a b 之和 示例 示例1 输入 a 1 b 2 输出 3 思路 位运算 观
  • e5服务器系列天梯图,最新的至强e5处理器天梯图

    有很多朋友都非常关注cpu市场的情况 因为一款CPU性能的好坏 决定了我们电脑的运算能力高低 CPU的种类多种多样 性能也不尽相同 今天我们主要关注的是英特尔e5处理器系列 为了直观对比e5系列cpu的性能情况 我们可以参考至强e5处理器天
  • egg-jwt 初探

    egg jwt 初探 什么是 egg jwt 我们都知道前后端交互离不开做用户验证 常见的有两种 后端将 sessionId 写到用户的 cookie 里 用户每次请求都会通过 cookie 再把 sessionId 传给后端 从而达到用户
  • 网络工程师:你是否真的已经倒下了?

    当前 阴魂笼罩在 网络管理员 网络工程师 这个职业上 干活比谁都累 工资比谁都低 不少人认为这个职业不再是高端的技术型人才 难道 网络工程师 你是否真的已经倒下了 不想低薪 请积极参与公司的业务 从最近我们公司招生来看 一个很明显的问题阴魂
  • 单元测试框架——Junit5

    文章目录 Junit 1 注解 2 断言 3 测试用例执行顺序 4 测试套件Suite 1 指定多个类 2 指定包 5 参数化 1 单参数 2 多参数 3 文件注入 6 动态参数 Junit Junit是一个开源的用于Java语言的单元测试
  • Maven系列(一):安装、配置Settings.xml配置文件与使用

    安装与使用 今天博主将为大家分享一下Maven的下载与安装 不喜勿喷 如有异议欢迎讨论 以下所写内容均与以前的文章有联系可以前往博文查看 陈永佳的博客 Maven 前言 首先 Maven是基于项目对象模型 POM project objec