Maven的下载

在Maven的官网即可下载,点击访问Apache Maven

下载后解压即可,解压后目录结构如下:

Maven常用配置

在配置之前请将JDK安装好。

1. 环境变量配置

添加M2_HOME:对应Maven的解压目录即可。

编辑Path环境变量:

测试,在cmd窗口输入mvn -v查看

显示如下即配置成功:

2. 修改配置文件

通常我们需要修改解压目录下conf/settings.xml文件,这样可以更好的适合我们的使用。

  • 此处注意:所有的修改一定要在注释标签外面,不然修改无效。Maven很多标签都是给的例子,都是注释掉的。

文章最后附上我的整个Settings.xml文件配置。

1. 本地仓库位置修改

在<localRepository>标签内添加自己的本地位置路径

 <!-- 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:\tools\repository</localRepository>

2. 修改maven默认的JDK版本

在<profiles>标签下添加一个<profile>标签,修改maven默认的JDK版本。

 <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>

3. 添加国内镜像源

添加<mirrors>标签下<mirror>,添加国内镜像源,这样下载jar包速度很快。默认的中央仓库有时候甚至连接不通。一般使用阿里云镜像库即可。这里我就都加上了,Maven会默认从这几个开始下载,没有的话就会去中央仓库了。

<!-- 阿里云仓库 -->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror> <!-- 中央仓库1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror> <!-- 中央仓库2 -->
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>

常用IDE下配置Maven

目前常用的开发工具如idea,eclipse都自身集成了一个版本的Maven。但是通常我们使用自己已经配置好的Maven。

IDEA下配置Maven

1:此处修改为自己解压的Maven目录

2:勾选Override,修改为自己目录下的settings.xml目录

3:修改为自己的本地仓库地址,一般会自动识别。

此处勾选,当修改pom文件时,Maven就能帮我们自动导包了。

Eclipse下配置Maven

  1. 将eclipse使用的Maven修改为自己的。点击add后选择自己Maven的安装目录即可。添加好之后记得勾选
  2. 将所有的settings修改为自己Maven目录下的conf/settings.xml.点击Update Settings按钮,下面的Local Respository会自动识别出来。
  3. 附:完整的Settings.xml文件

  4. <?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>
    -->
    <localRepository>D:\tools\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>alimaven</id>
    <mirrorOf>central</mirrorOf>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
    </mirror> <!-- 中央仓库1 -->
    <mirror>
    <id>repo1</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://repo1.maven.org/maven2/</url>
    </mirror> <!-- 中央仓库2 -->
    <mirror>
    <id>repo2</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://repo2.maven.org/maven2/</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>
    --> <!--
    | 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配置教程的更多相关文章

  1. Maven配置教程详解

    Maven的安装与配置 一.在https://www.cnblogs.com/zyx110/p/10799387.html中下载以下maven安装包 解压缩即可 根据你的安装路径配置maven环境变量 ...

  2. maven配置错误之Unable to import maven project: See logs for details

    很多朋友在初次使用maven时,都会出现这个问题. 一加载maven项目,即会报出Unable to import maven project这样的错误,哪怕是新的maven项目也不例外. 我查阅了很 ...

  3. Maven安装环境变量配置教程(带图)

    Maven安装配置环境变量教程 什么是maven:Maven是一个软件项目管理和综合工具.基于项目对象模型(POM)的概念,Maven可以从一个中心资料片管理项目构建,报告和文件. (简单来说就是,安 ...

  4. Ubuntu下Maven配置与Maven项目创建教程

    一. Ubuntu下Maven配置 windows下Maven配置参考http://www.cnblogs.com/LexMoon/p/JavaMaven.html ubuntu下Maven地址htt ...

  5. jdk配置及maven配置

    jdk配置及maven配置 >>>>>>>>>>>>>>>>>>>>>&g ...

  6. IDEA 初始配置教程

    IDEA 初始配置教程 如果你是第一次使用 IDEA,或者对 IDEA 常用配置仍然不熟悉,那么本文就特别适合你. 本文只是根据我自己的使用经验来进行配置,不一定适合所有的情况,但是对你肯定会有帮助. ...

  7. 史上最简单的ButterKnife配置教程

    网上的教程感觉都是抄来抄去,没一个靠谱的 还是自己丰衣足食搞一个ButterKnife配置教程吧.. 我的Android Studio版本是3.3. 1.dependencies中添加依赖 imple ...

  8. maven配置和下载

    下载链接:http://maven.apache.org/docs/ 以maven3.0.4为例,eclipse以kepler为例 环境变量的配置 1.系统变量-新建-变量名:MAVEN_HOME-变 ...

  9. Maven配置详见

    CSDN 2016博客之星评选结果公布    [系列直播]零基础学习微信小程序!      "我的2016"主题征文活动   博客的神秘功能 maven 配置详解 标签: mave ...

随机推荐

  1. report for PA1

    说明:最近特别忙,都没有时间写blog,好多遇到的问题都没能记下来,下面是PA1的报告主要记录了nemu debuger一些功能的实现方式和实现中遇到的问题,代替一下blog (申明:This is ...

  2. C lang:Array_Multidimensional arrays

    #include<stdio.h> #include<windows.h> #define YEARS 5 #define MONTHS 12 void color(short ...

  3. Vue-Cli 3.0 中配置高德地图

    vue 中使用高德地图有两种方式 一.vue-amap 组件 官网: https://elemefe.github.io/vue-amap/#/ 开始的时候是打算用这个组件做地图功能的,但是尝试之后存 ...

  4. ERROR 1366 (HY000): Incorrect string value: '\xE9\x83\x91\xE5\xB7\x9E' for column 'aa' at row 1 MySQL 字符集

    ERROR 1366 (HY000): Incorrect string value: '\xE9\x83\x91\xE5\xB7\x9E' for column 'aa' at row 1创建表之后 ...

  5. MYSQL5.7 INDEXES之如何使用索引(一)

    Most MySQL indexes (PRIMARY KEY, UNIQUE, INDEX, and FULLTEXT) are stored in B-trees. Exceptions: Ind ...

  6. kubernets学习笔记

    K8s CI :持续集成CD :持续交付 D --DeliveryCD :持续部署 D --Deployment Kubernetes Cluster: Masters: (3-host 做高可用)A ...

  7. LeetCode 49: 字母异位词分组 Group Anagrams

    LeetCode 49: 字母异位词分组 Group Anagrams 题目: 给定一个字符串数组,将字母异位词组合在一起.字母异位词指字母相同,但排列不同的字符串. Given an array o ...

  8. Deepnude算法“tuo”衣服

    PS:我不是偷窥狂.我是技术的爱好者 换脸视频后AI又出偏门应用:用算法“tuo”女性衣服 据美国科技媒体Motherboard报道,一名程序员最近开发出一款名叫DeepNude的应用,只要给Deep ...

  9. 双系统卸载ubuntu

    转载自https://www.jianshu.com/p/30795695be95 如果开机是这样子的,就是ubuntu引导windows(专业名词gpt) ubuntu引导windows 那么先进w ...

  10. 【UR #5】怎样更有力气

    Problem Description 大力水手问禅师:"大师,很多事情都需要用很大力气才能完成,而我在吃了菠菜之后力气很大,于是就导致我现在非常依赖菠菜.我很讨厌我的现状,有没有办法少吃点 ...