头图

1、安装idea,正常在官网下载社区版的idea就可以满足一般使用,在安装中有一点需要注意:
image.png
就是选择java,这块如果选成了其他就会在使用时存在编译问题,也就是其语言的编译器;
2、闲话不多说,直接上maven,maven是java里面的负责获取所需jar的工具,我的理解就是一个jar包自动获取仓库,可以这么理解,有点python中pip的味道,但是这个是需要添加配置文件的,所以起初如果是自己安装的maven就需要在idea中手动选择,如果是默认的,自己把maven需要的配置文件一定要配置好(友情提示:如果是新手使用maven在刚开始进入idea的时候,先不要创建工程,进去idea后,配置好对应maven的所需配置后,再进行maven的项目构建,以熟悉maven配置的地方,以便之后定位相关配置问题,或者重新下载maven知道怎么处理):
在idea的setting里面直接搜索maven:
1、我这里选择的是idea自己自带的maven,如果要用自己的,则在maven home path那块选择即可:
2、maven中最重要的两个目录,.m2\settings.xml的目录,这个是maven自己默认的,也可以自己手动修改,此目录是maven的配置文件,里面最核心的地方我觉得就是指定下载jar的地址(通常要选国内的),另一个是repository的目录,这个是maven下载后的jar存储仓库地址,建议选择除系统C盘以外的其他盘符:
image.png
3、setting.xml的配置及简单说明
官方配置文档的地方:
https://maven.apache.org/sett...
这里面用我已经踩过的xml,来说明
附上阿里云的仓库地址:
https://maven.aliyun.com/repo...
spring的:
https://maven.aliyun.com/repo...
这里面我采坑的关键点就在于仓库地址选择的地方:
image.png
也就是下载spring就要在这里添加spring的仓库地址(这里踩过坑,在之后如果没有添加这块,会在后面报spring相关模块找不到的异常):
image.png
<?xml version="1.0" encoding="UTF-8"?>
<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">

<!-- 2021-12-18 凡二先生 本地仓库的位置 -->
<localRepository>D:\javaWorkspace\repository</localRepository>

<!-- 2021-12-18 凡二先生 Apache Maven 配置 -->
<pluginGroups/>
<proxies/>

<!-- 2021-12-18 凡二先生 私服发布的用户名密码 -->
<servers>
    <server>
        <id>releases</id>
        <username>admin</username>
        <password>yunjifen</password>
    </server>
    <server>
        <id>snapshots</id>
        <username>admin</username>
        <password>yunjifen</password>
    </server>
</servers>

<!-- 2021-12-18 凡二先生 阿里云镜像 -->
<mirrors>
    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>https://maven.aliyun.com/repository/public</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>
<profiles>
    <!-- 全局JDK1.8配置 -->
    <profile>
        <id>jdk1.8</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>1.8</jdk>
        </activation>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <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>

    <!-- 2021-12-18 凡二先生 Nexus私服配置: 第三方jar包下载 -->
    <profile>
        <id>dev</id>
        <repositories>
            <repository>
                <id>nexus</id>
                <url>http://nexus.xxxx.cn:8081/repository/maven-public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>maven-public</id>
                <name>Public Repositories</name>
                <url>http://nexus.xxxx.cn:8081/repository/maven-public/</url>
            </pluginRepository>
        </pluginRepositories>
    </profile>

    <!-- 2021-12-18 凡二先生 阿里云配置: 提高国内的jar包下载速度 -->
    <profile>
        <id>ali</id>
        <repositories>
            <repository>
                <id>alimaven</id>
                <name>aliyun maven</name>
                <url>https://maven.aliyun.com/repository/spring</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>alimaven</id>
                <name>aliyun maven</name>
                <url>https://maven.aliyun.com/repository/public</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>alimaven</id>
                <name>aliyun maven</name>
                <url>https://maven.aliyun.com/repository/spring</url>
            </pluginRepository>
            <pluginRepository>
                <id>alimaven</id>
                <name>aliyun maven</name>
                <url>https://maven.aliyun.com/repository/public</url>
            </pluginRepository>
        </pluginRepositories>
    </profile>

</profiles>

<!-- 激活配置 -->
<activeProfiles>
    <activeProfile>jdk1.8</activeProfile>
    <activeProfile>dev</activeProfile>
    <activeProfile>ali</activeProfile>
</activeProfiles>

</settings>

4、以上步骤就绪后,就可以进行maven项目的创建了,在project里面新建maven工程,配置根据自己要创建的项目情况而设定:
image.png
此处根据实际情况命名:
image.png
在下一步的时候也会有让配置maven的地方,核对下是不是自己在setting配置的位置,当然也可直接创建maven的时候再这里配置,我写的前面步骤,是为了更好的加深映象:
image.png
直接下一步就行,由于配置文件无问题,下载对应的maven包后,会build success,也是预料之中:
image.png
5、下来maven相关的配置及仓库选择前提就打好了,开始maven的使用,此处就涉及maven第二个关键配置文件pom.xml,此文件就是用来获取对应jar包的,以spring为例,也就是之前也配置好spring国内阿里源地址:
image.png
在pom.xml这个dependencies地方加入对应的获取包名:
image.png
<!-- 2021-12-18 凡二先生 Spring核心基础依赖-->

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>5.2.1.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
  <version>5.2.1.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-beans</artifactId>
  <version>5.2.1.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-expression</artifactId>
  <version>5.2.1.RELEASE</version>
</dependency>
<!-- 2021-12-18 凡二先生 日志相关-->
<dependency>
  <groupId>commons-logging</groupId>
  <artifactId>commons-logging</artifactId>
  <version>1.2</version>
</dependency>
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.17</version>
</dependency>

在此之前可以在阿里的spring仓库上https://developer.aliyun.com/...,看看目前提供的spring版本:
image.png
添加完成后,maven一般会自动下载资源
image.png
如果没有下载可以手动进行资源获取,在pom.xml任意位置点击鼠标右键,选择下载资源即可:
image.png
到此结束,spring所需的环境依赖到此结束,如果有需要其他组件的可以继续添加配置即可!

希望对大家有帮助!


凡二先生
1 声望2 粉丝

谷隐.凡二