在Mac系统下为SpringBoot 配置Maven 【避坑完整版】

前提背景

电脑罢工,操作系统重装,不仅有大量的软件需要安装,还有很多开发环境需要配置。

就在今天配置Maven的时候各种坑,写下来供大家参考。

一、在讨论安装Maven前先安装一下JDK,方式很多,我这里有个比较快的办法,利用IDEA安装。

        1.1 IDEA 安装JDK :随便创建一个项目

        

        1.2 找自己想要的JDK就好了
 

        1.3 验证是不是JDK 是好了

        命令:

        

java -version

        能正常显示对应版本号就说明好了,如下图

        1.4 创建环境变量文(如果没有创建过,这个一定要创建,如果创建过忽略)

        命令:

touch .bash_profile

二、配置Maven

        2.1 查找相应版本的Maven  点击

        2.2 下载

        

        2.2 解压到用户目录

                

        2.3 修改配置

                

        2.4 修改 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>--><localRepository>${user.home}/.m2/repository</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>--></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>aliyunmaven</id><mirrorOf>*</mirrorOf><name>阿里云公共仓库</name><url>https://maven.aliyun.com/repository/public</url></mirror><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-11</id><activation><activeByDefault>true</activeByDefault><jdk>11</jdk></activation><properties><maven.compiler.source>11</maven.compiler.source><maven.compiler.target>11</maven.compiler.target><maven.compiler.compilerVersion>11</maven.compiler.compilerVersion></properties></profile>
​    <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>

        2.5 修改环境变量

                2.5.1 命令

                

open -e .bash_profile

                2.5.2 把Maven 配置进去

export MAVEN_HOME=/Users/barry/maven  【注意这里的路径是你自己的路】
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH


                2.5.3 刷新配置

        命令:

        

source .bash_profile 

                2.5.4 验证是否成功

命令:

mvn -v

正常显示对应版本号代表成功

三、IDEA  Maven 配置

刷新项目Maven 就正常了

总结

这里有几个重点,主要是生成环境变量文件,如果没有生成就谈不上配置。折腾是免不了的,分享给大家,原创不易,转载请注明出处

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

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Postman介绍和快速使用

Postman 是什么&#xff1f; Postman 是一个流行的API&#xff08;Application Programming Interface&#xff09;开发工具&#xff0c;它使得开发者可以很容易地创建、测试、共享和文档化API。Postman 提供了一个友好的用户界面&#xff0c;来发送HTTP请求&#xff0c;接收响…

prince2和Pmp哪个含金量高?

先来说下 prince 2 和 pmp 的区别 一、prince 2 是什么&#xff1f;跟PMP有什么区别&#xff1f; prince2 是 PRojetcts IN Controllde Environments 的简称&#xff0c;中文意思是受控环境下的项目&#xff0c;指的就是受控环境下的项目管理方法论。 如果知道 PMP 的可以简…

健康卤味思想引领市场新潮流,卤味市场迎来健康变革

健康卤味思想正在逐渐渗透到卤味市场中&#xff0c;引领着消费者对于卤味产品的选择和需求。这一变革不仅为消费者带来了更加健康、美味的卤味产品&#xff0c;也为卤味市场注入了新的活力。 一、健康卤味思想的兴起 随着消费者对于健康饮食的关注度不断提高&#xff0c;健康卤…

带你了解OpenCV4工业缺陷检测的六种方法

文章目录 OpenCV4工业缺陷检测的六种方法机器视觉缺陷检测1. 工业上常见缺陷检测方法方法一&#xff1a;基于简单二值图像分析实现划痕提取&#xff0c;效果如下&#xff1a;方法二&#xff1a;复杂背景下的图像缺陷分析&#xff0c;基于频域增强的方法实现缺陷检测&#xff0c…

ipfire

安装 网卡地址配置 非常重要&#xff0c;配置不正确&#xff0c;影响ipfire正常工作 setup可以进入设置界面 配置 创建端口转发规则 设置端口转发是一项非常常见的任务。本指南解释了如何快速设置端口转发规则。请查看防火墙规则参考以了解更多说明。 技术背景 端口转发…

GPT-4.5!!!

GPT-4 还没用明白&#xff0c;GPT-4.5 就要发布了。 最近&#xff0c;OpenAI 泄露了 GPT-4.5 的发布页面&#xff0c;除了进一步增强复杂推理和跨模态理解&#xff0c;GPT-4.5 增加了一个更加强大的功能——3D。 3D 功能的进一步支持&#xff0c;也就意味着多模态最后一块版图…

webview 的 title 和 url

在Appium以混合型App进行自动化操作时&#xff0c;遇到WebView时切换至WebView才能进行操作。当遇到多个WebView时&#xff0c;可以利用 title 和 url 切换至相应的 WebView。

测试用例设计方法六脉神剑——第五剑:化气为型,场景用例破云 | 京东物流技术团队

1 引言 前几篇文章主要针对单点功能的测试用例设计方法展开介绍。然而&#xff0c;当拿到一个测试任务时&#xff0c;并非先关注某个功能的细节测试&#xff0c;而是先要使用场景法对主要业务流程和主要功能展开测试&#xff0c;当业务场景没有问题后&#xff0c;再使用等价类…

k8s集群内部署nacos集群

一、前言 在k8s集群中部署nacos集群需要用到以下服务setafulset、pv、pvc、service、configmap&#xff0c;setafulset用来管理nacos服务&#xff0c;因为nacos服务是有状态服务&#xff0c;所以需要使用setafulset&#xff0c;pv、pvc用来挂载存储nacos数据的路径&#xff0c;…

数据结构:图文详解 队列 | 循环队列 的各种操作(出队,入队,获取队列元素,判断队列状态)

目录 队列的概念 队列的数据结构 队列的实现 入队 出队 获取队头元素 获取队列长度 循环队列的概念 循环队列的数据结构 循环队列的实现 判断队列是否为空 判断队列是否已满 入队 出队 得到队头元素 得到队尾元素 队列的概念 队列&#xff08;Queue&#xff0…

音频世家索尼:醇音典范 一脉相承! 参展第九届中国(广州)国际耳机展,懂音乐懂生活更懂你

第九届中国&#xff08;广州&#xff09;国际耳机展于2023年12月16日至12月17日&#xff0c;在广州白云国际会议中心一楼举行。浸润于音频行业70余年的“音频世家——索尼&#xff0c;秉持“For The Music”&#xff08;为音乐而生&#xff09;的音频品牌理念&#xff0c;将惊喜…

2024年【北京市安全员-C3证】考试题及北京市安全员-C3证考试试卷

题库来源&#xff1a;安全生产模拟考试一点通公众号小程序 北京市安全员-C3证考试题是安全生产模拟考试一点通总题库中生成的一套北京市安全员-C3证考试试卷&#xff0c;安全生产模拟考试一点通上北京市安全员-C3证作业手机同步练习。2024年【北京市安全员-C3证】考试题及北京…