`
sanry
  • 浏览: 35391 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

现有web系统替换成Spring Boot2框架 之1 搭建Maven环境

阅读更多

安装

<!--[if !supportLists]-->1. <!--[endif]-->maven运行,需要用到jdk,安装maven之前,先要确保系统中安装了jdk 1.4以上的版本。

<!--[if !supportLists]-->2. <!--[endif]-->下载安装包。进入maven官网:http://maven.apache.org/

<!--[if !supportLists]-->3. <!--[endif]-->将下载的文件解压,位置任意。解压后得到的文件结构如下图。其中bin文件夹下,即为maven的命令脚本。

4. 修改环境变量。将bin文件夹的绝对路径,添加到系统的环境变量path中。

<!--[if !supportLists]-->5. <!--[endif]-->验证maven安装是否成功。执行命令mvn -v检查是否安装成功。

Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T02:41:47+08:00)

Maven home: D:\apache-maven-3.6.0\bin\..

Java version: 1.8.0_191, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_191\jre

Default locale: zh_CN, platform encoding: GBK

OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

配置镜像地址配置

maven默认连接的maven中央仓库,下载依赖库时速度很慢,所以一般将其配置为国内的镜像地址,比如阿里云maven镜像。

<!--[if !supportLists]-->1. <!--[endif]-->拷贝配置文件。将maven安装目录下的conf/settings.xml拷贝到当前用户目录下的.m2文件夹下。这样做的目的是,修改配置文件时,不会影响其他用户,此文件只对当前用户有效。

 

<!--[if !supportLists]-->2. <!--[endif]-->修改配置文件。在mirrors元素下,添加阿里云镜像配置,即将阿里云maven作为了中央仓库的镜像,下载依赖库时,是从阿里云下载

<mirror>

      <id>alimaven</id>

      <mirrorOf>central</mirrorOf>

      <name>Human Readable Name for this Mirror.</name>

      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

    </mirror>

id/name可以自由决定,只要本地唯一即可。

 

mirrorOf,指此配置要作为谁的镜像,按上图配置为central即表示此配置为中央仓库的镜像,所有对于中央仓库的请求都会转至该镜像

项目配置

新建mavn项目配置pom.xml:

<!--[if !supportLists]-->1. <!--[endif]-->添加parent标签,继承spring-boot-starter-parent,以获取一些默认配置:

 

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>2.1.0.RELEASE</version>

<relativePath/> 

</parent>

 

2. 如果需要把项目打包成一个可执行的jar包,需要添加Maven插件:

 

<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

</plugins>

</build>

 

3. Spring-boot其他依赖库:

<!--核心starter,包含auto-configuration,logging and YAML-->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter</artifactId>

</dependency>

 

<!--单元测试-->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

</dependency>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics