idea+maven(国内源)安装spring环境配置+采坑

idea安装:

官网:

下载 IntelliJ IDEA:JetBrains 功能强大、符合人体工程学的 Java IDE

1、安装idea,正常在官网下载社区版的idea就可以满足一般使用,在安装中有一点需要注意,我安装的java所以勾选了这个,此处也可以不进行勾选:

maven:

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盘以外的其他盘符:

 

3)setting.xml的配置及简单说明
官方配置文档的地方:
https://maven.apache.org/settings.html
这里面用我已经踩过的xml,来说明
附上阿里云的公共仓库地址:
https://maven.aliyun.com/repository/public
spring的:
https://maven.aliyun.com/repository/spring
这里面我采坑的关键点就在于仓库地址选择的地方:

也就是下载spring就要在这里添加spring的仓库地址(这里踩过坑,在之后如果没有添加这块,会在后面报spring相关模块找不到的异常):

附上源配置: 

<?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>
<mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
</mirror>

 以及在maven设置的runner栏中的vm options参数中增加

-DarchetypeCatalog=local

 4)以上步骤就绪后,就可以进行maven项目的创建了,在project里面新建maven工程,配置根据自己要创建的项目情况而设定:

此处根据实际情况命名:

在下一步的时候也会有让配置maven的地方,核对下是不是自己在setting配置的位置,当然也可直接创建maven的时候再这里配置,我写的前面步骤,是为了更好的加深印象:

直接下一步就行,由于配置文件无问题,下载对应的maven包后,会build success,也是预料之中:

5、下来maven相关的配置及仓库选择前提就打好了,开始maven的使用,此处就涉及maven第二个关键配置文件pom.xml,此文件就是用来获取对应jar包的,以spring为例,也就是之前也配置好spring国内阿里源地址:

在pom.xml这个dependencies地方加入对应的获取包名:

附上源配置:

<!-- 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仓库上:仓库服务,看看目前提供的spring版本:

 添加完成后,maven一般会自动下载资源:

如果没有下载可以手动进行资源获取,在pom.xml任意位置点击鼠标右键,选择下载资源即可:

到此结束,spring所需的环境依赖到此结束,如果有需要其他组件的可以继续添加配置即可! 

 希望对大家有帮助!

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谷隐凡二

相识便是缘,开启技术大门

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值