如何在IDEA上配置Maven


IDEA 全称 IntelliJ IDEA,是java语言开发的集成环境,IntelliJ在业界被公认为最好的Java开发工具之一, IDEA是JetBrains公司的产品,现在有逐步取代老牌Java开发工具Eclipse的趋势.那本人也是从Eclipse 转到IDEA.那刚转换过来时,确实很不适应,不过好在坚持使用了几天后,确实感觉IntelliJ IDEA比Eclipse更加智能.


Maven项目对象模型(POM),是一个项目管理工具可以通过一小段描述信息来管理项目的构建,报告和文档的软件。

在IDEA上配置Maven

1.Maven下载

  • apache-maven官网下载
  • 解压到英文路径下的目录
  • 创建本地仓库目录:LocalWarehouse[名字随便取]

2.Maven环境变量配置

  • 打开环境变量页面
  • 新建系统变量 M2_HOME
  • 在已有变量Path中引入M2_HOME
  • Win+R 输入cmd打开命令行,键入mvn -version验证是否成功

3.配置Maven仓库路径

  • 打开apache-maven-3.6.2\conf路径下的settings.xml文件,并按下图修改(第二张图的代码位置大概在50行附近)

  • 打开IDEA 选择File——Settings,如下设置
建议使用国内镜像,具体配置请参考:
或者访问阿里云仓库网址获取最新配置----2021年7月12日更新博客 --> (https://maven.aliyun.com/mvn/guide)
<?xml version="1.0" encoding="UTF-8"?>

    
    
    
    
    
    D:\my_maven_local_repository
    
    
        
            alimaven
            central
            aliyun maven
            http://maven.aliyun.com/nexus/content/repositories/central/
        
        
            alimaven
            aliyun maven
            http://maven.aliyun.com/nexus/content/groups/public/
            central
        
        
            central
            Maven Repository Switchboard
            http://repo1.maven.org/maven2/
            central
        
        
            repo2
            central
            Human Readable Name for this Mirror.
            http://repo2.maven.org/maven2/
        
        
            ibiblio
            central
            Human Readable Name for this Mirror.
            http://mirrors.ibiblio.org/pub/mirrors/maven2/
        
        
            jboss-public-repository-group
            central
            JBoss Public Repository Group
            http://repository.jboss.org/nexus/content/groups/public
        
        
            google-maven-central
            Google Maven Central
            https://maven-central.storage.googleapis.com
            
            central
        
        
        
            maven.net.cn
            oneof the central mirrors in china
            http://maven.net.cn/content/groups/public/
            central
        
    
    

  • 自动导包设置
  • 不联网状态下,让Maven使用本地仓库下载好的骨架: -DarchetypeCatalog=internal

4.我们可以更新一下本地仓库和远程仓库,这个样在pom.xml文件中添加依赖jia包的坐标时就可以很好的提示出来