【Maven基础】依赖插件管理工具

news2024/11/16 11:34:32

Maven

  • Maven 作用
  • Maven 安装
  • Maven 目录
  • Maven config settings
  • 创建 Maven 项目
  • 运行 Java 文件
  • Maven 坐标
  • 导入 Maven 项目
  • 依赖管理
    • 依赖配置
  • 依赖传递
    • 排除依赖
  • 依赖范围
  • 生命周期
    • test
    • 跳过 Test

Maven 作用

在这里插入图片描述

Maven 安装

在这里插入图片描述

Maven 目录

bin 存放可执行文件

config 存放 Maven 的配置文件

lib 存放 Maven 依赖 jar 包资源

Maven config settings

<?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.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.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.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>
  -->
  <localRepository>D:\apache-maven-3.9.6\mvn_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>

  <!-- TODO Since when can proxies be selected as depicted? -->
  <!-- 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>
    -->
  </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>alimaven</id>
      <mirrorOf>aliyun maven</mirrorOf>
      <url>http://maven.aliyun.com/nexus/content/groups/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 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 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>

创建 Maven 项目

创建的 Maven 项目下的 test 没有 resource 文件夹, 因为 test 下的 resource 不常用,如果需要,可以新建一个 Directory,创建 resource 文件

运行 Java 文件

在这里插入图片描述

生成一个 Target 文件,是 Java 项目编译后的字节码文件

Maven 坐标

什么是坐标?

Maven 中的坐标是资源的唯一标识,通过该坐标可以唯一定位资源位置

使用坐标来定义项目或引入项目中需要的依赖

Maven 坐标主要组成

groupld: 定义当前Maven项目隶属组织名称(通常是域名反写,例如:com.futao)
    
artifactld: 定义当前Maven项目名称(通常是模块名称,例如 order-service、goods-service)
    
version:定义当前项目版本号

在这里插入图片描述

导入 Maven 项目

在这里插入图片描述

依赖管理

依赖配置

在这里插入图片描述

在这里插入图片描述

<dependencies>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.4.7</version>
    </dependency>
</dependencies>

举例引入一个 logback-classic

可以在 Maven 仓库便捷引入

依赖传递

在这里插入图片描述

在这里插入图片描述

像这样,A依赖B,B依赖C,所以A也间接依赖着C模块

排除依赖

在这里插入图片描述
在这里插入图片描述

排除后

在这里插入图片描述

依赖范围

在这里插入图片描述

生命周期

在这里插入图片描述

在一套生命周期中,在运行后面的生命周期阶段,前面的阶段也会运行

在这里插入图片描述

注意,只会运行同一套的生命周期阶段,运行 insall 是不会运行 clean 的

test

在这里插入图片描述
在这里插入图片描述

跳过 Test

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1423779.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

etcd自动化安装配置教程

文章目录 前言一、简介1. 简介2. 特点3. 端口介绍 二、etcd安装教程&#xff08;单机版&#xff09;1. 复制脚本2. 增加执行权限3. 执行脚本4. 查看启动状态5. 卸载etcd 三、etcd安装教程&#xff08;集群版&#xff09;1. 复制脚本2. 增加执行权限3. 分发脚本4. 执行脚本5. 启…

Facebook的社交影响力:用户行为解析与趋势

在当今数字时代&#xff0c;社交媒体已经成为人们日常生活中不可或缺的一部分&#xff0c;而Facebook作为全球最大的社交平台之一&#xff0c;其社交影响力愈发显著。本文将深入分析Facebook的社交影响力&#xff0c;解析用户行为&#xff0c;同时探讨当前和未来的社交趋势。 社…

如何快速将 HTML 文件转换为 PDF

HTML表格是一种在网页上显示数据的通用且强大的方式。它们可用于创建简单的表&#xff08;例如日历&#xff09;或更复杂的表&#xff08;例如数据网格&#xff09;。在这篇博文中&#xff0c;我们将逐步学习如何在 C# 中创建 HTML 表格。本指南将为您提供在 C# 中有效创建 HTM…

MySQL运维实战(5.3) MySQL数据乱码的一些情况

作者&#xff1a;俊达 表数据乱码 表数据出现乱码的情况通常是由于数据的真实编码与相关参数不一致引起的&#xff0c;其中包括常见的参数如character_set_client、character_set_results、字段编码以及终端编码等。确保这些参数保持一致&#xff0c;可以有效预防和解决乱码问…

前端封装websocket类,实现消息注册和全局回调

实现消息注册和回调函数&#xff0c;实现全局使用同一个webscoket对象&#xff0c;并实现断线重连和心跳连接等功能&#xff0c;可以实现全局使用唯一实例&#xff0c;可以另外进行拓展配置 // WebSocket类对象 class WebSocketCli {// 构造函数constructor(url: string, opts…

如何更改Outlook阅读邮件时的默认字体?

如果收到的邮件中未指定字体&#xff0c;outlook默认使用宋体显示。 如果觉得不好看&#xff0c;可以进行更改。但不是在outlook中更改&#xff0c;outlook中只是修改编辑器中的字体&#xff0c;和纯文本邮件浏览的字体&#xff0c;不能更改未指定字体的HTML邮件的显示字体。 …

如何确保 Redis 集群的数据一致性?

当我们谈论Redis集群的数据一致性问题时&#xff0c;实际上我们是在探讨一个复杂且多维度的主题。 Redis作为一个高性能的键值存储数据库&#xff0c;在分布式环境下如何保证数据的一致性&#xff0c;是设计和使用Redis集群时需要重点考虑的问题。 下面&#xff0c;我将从多个角…

福禄克万用表使用注意事项

所需设备&#xff1a; 1、Fluke ADPT连接器&#xff1b; 2、Fluke 15B / 17B / 18B&#xff1b; 虽然福禄克万用表非常耐用&#xff0c;但是一旦电池漏液是非常糟糕的&#xff01; 定期查看电池是否漏液&#xff01; 定期查看电池是否漏液&#xff01; 定期查看电池是否…

SOLIDWORKS Simulation 2024增强新功能

SOLIDWORKS 2024 新功能前瞻| SOLIDWORKS Simulation 功能增强 • 性能增强功能 • 壳体的接合交互 • 网格性能 • 欠约束实体检测 • 增强型轴承接头 • 收敛检查图解 • 去耦合混合自由体模式 • 复制算例时排除网格和结果 • 新增在网格化后及分析完成后自动保存模…

推荐系统|召回_Swing召回通道

召回_Swing 模型 swing模型是ItemCF的一种改造 ItemCF的原理 举个例子。 ItemCF的存在的问题 有可能两篇不同类型的物品/笔记被分享到同一个微信群&#xff0c;从而提高了两个不同类型的视频被同一组人打开的概率。 而这只能说明这两个物品/笔记具有相同的受众&#xff0c;…

数据分析基础之《pandas(2)—基本数据操作》

一、读取一个真实的股票数据 1、读取数据 # 基本数据操作 data pd.read_csv("./stock_day.csv")data# 删除一些列&#xff0c;使数据简洁点 data data.drop([ma5,ma10,ma20,v_ma5,v_ma10,v_ma20], axis1)data 二、索引操作 1、numpy当中我们已经讲过使用索引选取…

幻兽帕鲁服务器Palworld游戏怎么更新?

自建幻兽帕鲁服务器进入Palworld游戏提示“您正尝试加入的比赛正在运行不兼容的游戏版本&#xff0c;请尝试升级游戏版本”什么原因&#xff1f;这是由于你的客户端和幻兽帕鲁服务器版本不匹配&#xff0c;如何解决&#xff1f;更新幻兽帕鲁服务器即可解决。阿里云百科aliyunba…

《Is dataset condensation a silver bullet for healthcare data sharing?》

一篇数据浓缩在医疗数据集应用中的论文。 其实就是在医疗数据集上使用了data condensation的方法&#xff0c;这里使用了DM的方式&#xff0c;并且新增了浓缩时候使用不同的网络。 1. 方法 数据浓缩DC的目的是&#xff1a; E x ∼ P D [ L ( φ θ O ( x ) , y ) ] ≃ E x ∼…

C#中的WebApi响应Accept头,自动返回xml或者json

Global.asax.cs中的Application_Start方法添加 GlobalConfiguration.Configuration.Formatters.Clear(); GlobalConfiguration.Configuration.Formatters.Add(new XmlMediaTypeFormatter()); GlobalConfiguration.Configuration.Formatters.Add(new JsonMediaTypeFormatter())…

Kerberos 安全认证

什么是Kerberos Kerberos是一种计算机网络授权协议&#xff0c;用来在非安全网络中&#xff0c;对个人通信以安全的手段进行身份认证。密码不在网络上传输&#xff0c;提高安全性。 简写名词 AS&#xff08;Authentication Server&#xff09; 认证服务器KDC&#xff08;Key…

Swagger学习使用

swagger升级导致访问ui页面地址不一样 方式一 依赖 <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.3.RELEASE</version></parent> <dependenc…

云打印机怎么连接手机?

现在越来越多的人使用手机来办公或学习。而当我们需要打印文件时,如何用云打印机连接手机就非常重要了。易绘创云打印服务非常实用&#xff0c;那么易绘创云打印机又该怎么连接手机&#xff1f;下面就让我们一起来了解吧。 云打印机怎么连接手机&#xff1f; 当下云打印机连接…

adb 无线连接 操作Android设备

最近集五福活动比较热门 可以用这个工具 用自己擅长的语言写一个循环程序 运行起来就可以 自动帮我们 看视频得福卡了 很方便 while (true) {sleep(mt_rand(15, 25));system(adb shell input swipe 500 2000 500 1000 100); } 1. 首先下载 安卓开发工具 adb adb网盘链接 链接…

第17次修改了可删除可持久保存的前端html备忘录:增加年月日星期,增加倒计时,更改保存区名称可以多个备忘录保存不一样的信息,匹配背景主题:现代深色

第17次修改了可删除可持久保存的前端html备忘录&#xff1a;增加年月日星期&#xff0c;增加倒计时&#xff0c;更改保存区名称可以多个备忘录保存不一样的信息&#xff0c;匹配背景主题&#xff1a;现代深色 备忘录代码&#xff1a; <!DOCTYPE html> <html lang&quo…

C#用正则表达式判断字符串是否纯数字vs用Char.IsDigit 方法遍历字符数组是否纯数字

目录 一、使用的方法 1.正则表达式 2.Char.IsDigit 方法 二、源码 1.源代码 2.生成效果 一、使用的方法 1.正则表达式 在程序运行过程中&#xff0c;经常需要用户输入数字信息&#xff0c;如输入员工年龄、工资等。使用正则表达式Regex类的IsMatch方法&#xff0c;可以有…