Maven下载安装与配置、Idea配置Maven(详细版)

算法星云
• 阅读 835
Maven是Apache软件基金会的一个开源项目,是一款优秀的项目构建工具,它主要用于帮助开发者管理项目中jar以及jar之间的依赖关系,最终完成项目编译,测试,打包和发布等工作。

前面我们已经简单介绍了Maven的概念、特点及使用,本篇文章就来给大家出一个详细的安装和配置教程,还没有安装Maven的小伙伴要赶紧收藏起来哦!

首先给大家解释一下为什么学习Java非要学Maven不可。

为什么要学习Maven?

大家在读这篇文章之前大部分人都已经或多或少的经历过项目,说到项目,在原生代码无框架的时候,最痛苦的一件事情就是要在项目中导入各种各样使用的jar包,jar太多就会导致项目很难管理。需要考虑到jar包之间的版本适配的问题还有去哪找项目中使用的这么多的jar包,等等。这个时候,Maven就出现了,它轻松解决了这些问题。

说的直白一点,maven就相当于个三方安装包平台,可以通过一些特殊的安装方式,把一些三方的jar包,装到咱们自己的项目中。

Maven安装以及配置

Maven下载地址:https://maven.apache.org/

打开欢迎界面点击download下载

Maven下载安装与配置、Idea配置Maven(详细版)

Maven下载安装与配置、Idea配置Maven(详细版)

Maven下载安装与配置、Idea配置Maven(详细版)

在这里我们安装的是Maven的3.6.3版本,下载好之后是一个压缩包

Maven下载安装与配置、Idea配置Maven(详细版)

在电脑中找一个地方把压缩包解压,解压后

Maven下载安装与配置、Idea配置Maven(详细版)

配置环境变量

Maven下载安装与配置、Idea配置Maven(详细版)

在这儿一定要注意配置路径

Maven下载安装与配置、Idea配置Maven(详细版)

点击开始菜单 ->搜查框输入:cmd 回车 -> 出现Maven版本号说明安装成功

Maven下载安装与配置、Idea配置Maven(详细版)

Maven配置本地仓库

如何将下载的 jar 文件存储到我们指定的仓库中呢?需要在 maven 的服务器解压的文件中找到 conf 文件夹下的 settings.xml 文件进行修改,如下图所示:

Maven下载安装与配置、Idea配置Maven(详细版)

进入文件夹打开settings.xml文件

Maven下载安装与配置、Idea配置Maven(详细版)

因为默认的远程仓库地址,是国外的地址;在国内为了提高下载速度,可在如图所示位置配置阿里云仓库

Maven下载安装与配置、Idea配置Maven(详细版)

在idea工具中配置Maven

打开idea-----点击File-----点击New Projects Settings-----点击Setting for New Projects…

Maven下载安装与配置、Idea配置Maven(详细版)

这样,我们的Maven就安装配置完成了。

编程学习,从云端源想开始,课程视频、在线书籍、在线编程、一对一咨询……你想要的全部学习资源这里都有,重点是统统免费!点这里即可查看

附上我们一个配置文件,里面其实很大篇幅都是注释,为我们解释标签的用途,核心是咱们配置的远程中央仓库地址;在有的公司,是有自己的远程私有仓库地址的,配置方式跟中央仓库配置基本雷同,可能有一些账号密码而已.

<?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.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>
        -->
    </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>aliyun</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>
        -->

    </profiles>
    
    <!-- activeProfiles
     | List of profiles that are active for all builds.
     |
    <activeProfiles>
      <activeProfile>alwaysActiveProfile</activeProfile>
      <activeProfile>anotherAlwaysActiveProfile</activeProfile>
    </activeProfiles>
    -->
</settings>
点赞
收藏
评论区
推荐文章
美凌格栋栋酱 美凌格栋栋酱
7个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
推荐学java 推荐学java
3年前
推荐学java——Maven初识
Maven介绍Maven是Apache下开源的Java项目管理工具,对软件项目提供构建与依赖管理。其为Java项目提供了统一的管理方式,已成为业界标准。Maven下载安装官网下载地址:https://maven.apache.org/推荐下载压缩包版本,然后解压到本地不带中文路径的目录下,我这里解压在了D盘的根目录下:D:\ProgramF
Wesley13 Wesley13
3年前
SSM 框架
SSM框架04使用maven创建web项目<p<spanstyle"fontsize:14px;"&nbsp;&nbsp;&nbsp;&nbsp;本篇介绍使用MAVEN来管理jar包,就不用一个一个去添加和下载jar包了,直接在maven配置文件中配置就可以了,maven可以帮助我们自动下载。<spanstyle"co
kenx kenx
4年前
Maven 基础标签之版本管理和冲突解决
前言我们在做java项目的时候由于jar包太多,我们就需要使用maven做项目管理,管理项目的jar包依赖,包括打包上线maven基础Maven是一个项目管理工具,主要用于项目构建,依赖管理,项目信息管理每个maven项目根目录都会有一个pom.xml文件,负责项目构建,依赖管理在这个文件里面,你只需要添加相应的jar包坐标配置,maven就会自动
Stella981 Stella981
3年前
Maven项目使用打包时使用本地jar包库
在使用maven管理项目时,有时候我们可能会使用一些第三方的jar包依赖库,但是这些jar包依赖库又没有在共有的maven仓库。通常只能下来放到本项目的lib目录下。但是我们打包时如果不做处理,那么打包后的fatjar中不会有lib文件夹中的相关jar包。打包后无法运行起来,因此需要做特殊处理,让maven打包时能够把使用到外部jar打进去。主要就是在
Stella981 Stella981
3年前
CentOS 7 安装 Gradle
       Java生态体系中有三大构建工具:Ant、Maven和Gradle。其中,Ant是由Apache软件基金会维护;Maven这个单词来自于意第绪语(犹太语),意为知识的积累,最初在JakataTurbine项目中用来简化构建过程;Gradle是一个基于ApacheAnt和ApacheMaven概念的项目自动化构建开源工具,它使用一种基于G
Wesley13 Wesley13
3年前
01.Flink笔记
Flink开发环境部署配置Flink是一个以Java及Scala作为开发语言的开源大数据项目,代码开源在github上,并使用maven来编译和构建项目。所需工具:Java、maven、Git。本次操作是在windows环境下。一、工具安装Java配置(略)maven配置1.
Stella981 Stella981
3年前
Maven实战(一)安装与配置
1\.简介  Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具.  如果你已经有十次输入同样的Anttargets来编译你的代码、jar或者war、生成javadocs,你一定会自问,是否有一个重复性更少却能同样完成该工作的方法。Maven便提供了这样一种选
Stella981 Stella981
3年前
Idea下maven的配置和使用
  maven的主要功能就是依赖管理,jar包仓库。和C中的NuGet仓库差不多。另外也提供打包构建,启动插件等功能。下面主要讲一下,在使用Idea开发时,maven的配置和使用。maven的安装和配置  maven(3.6.1)的下载地址:https://idlestudio.ctfile.com/fs/14960372382
Stella981 Stella981
3年前
Maven总结
何为maven?1.Maven主要是基于Java平台的项目构建,依赖管理和项目信息2.Maven是优秀的构建工具,跨平台,消除构建的重复,抽象了一个完整的构建生命周期模型,标准化构建过程3.管理分布的项目信息,版本控制系统,轻松获取项目文档,测试报告,静态分析报告,版本日志报告等4.极限编程(XP)