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所需的环境依赖到此结束,如果有须要其余组件的能够持续增加配置即可!
心愿对大家有帮忙!
发表回复