关于idea:ideamavenspring安装环境初尝试采坑

8次阅读

共计 4927 个字符,预计需要花费 13 分钟才能阅读完成。

1、装置 idea,失常在官网下载社区版的 idea 就能够满足个别应用,在装置中有一点须要留神:

就是抉择 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 盘以外的其余盘符:

3、setting.xml 的配置及简略阐明
官网配置文档的中央:
https://maven.apache.org/sett…
这外面用我曾经踩过的 xml,来阐明
附上阿里云的仓库地址:
https://maven.aliyun.com/repo…
spring 的:
https://maven.aliyun.com/repo…
这外面我采坑的关键点就在于仓库地址抉择的中央:

也就是下载 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>

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 仓库上 https://developer.aliyun.com/…,看看目前提供的 spring 版本:

增加实现后,maven 个别会主动下载资源

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

到此结束,spring 所需的环境依赖到此结束,如果有须要其余组件的能够持续增加配置即可!

心愿对大家有帮忙!

正文完
 0