手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

Idea如何使用Gradle创建并打包Springboot项目

时间:2024-10-14 21:36:48

1、点击File -> New Project 新建一个Gradle项目

Idea如何使用Gradle创建并打包Springboot项目
Idea如何使用Gradle创建并打包Springboot项目

2、输入GAV并点击下一步,选择Gradle的路径,可以选择默认的或者使用本地的Gradle(不推荐默认的,下载速度比较慢),接着输入项目路径点击finish等待初始化完成。

Idea如何使用Gradle创建并打包Springboot项目

3、如果需要的话,在build.gradle文件中切换依赖下载地址为国内镜像地址,以方便后续操作,地址为:http://maven.aliyun.com/nexus/content/groups/public/

Idea如何使用Gradle创建并打包Springboot项目

4、引入Spri艘绒庳焰ngboot插件,在build.gradle文件plugins中维护版本并apply:id 'org.springframework.boot' version '2.1.3.RELEASE'apply plugin: 'io.spring.dependency-management'

Idea如何使用Gradle创建并打包Springboot项目

5、引入Spri艘绒庳焰ngboot依赖,在build.gradle文件dependencies中加入web依赖,并在java文件夹下面编佯鲅烫侬写启动类测试。implementation 'org.springframework.boot:spring-boot-starter-web'

Idea如何使用Gradle创建并打包Springboot项目
Idea如何使用Gradle创建并打包Springboot项目

6、常规方式启动或者直接在右侧Gradle工具栏尝试启动项目,访问localhost:8080 进行测试。

Idea如何使用Gradle创建并打包Springboot项目
Idea如何使用Gradle创建并打包Springboot项目

7、打成jar包并尝试运行,点击右侧boot亭盍誓叭Jar,在项目路径下build/libs下找到jar包并在命令行运行。同样访问localhost:8080 进行测试。(注意先关闭上一次打开的项目,或者切换端口打包运行)

Idea如何使用Gradle创建并打包Springboot项目
Idea如何使用Gradle创建并打包Springboot项目
Idea如何使用Gradle创建并打包Springboot项目

8、修改配置,加入war插件,并使主类继承SpringBootServletInitializerapply plugin: 'war'

Idea如何使用Gradle创建并打包Springboot项目
Idea如何使用Gradle创建并打包Springboot项目

9、点击右侧bootWar打包,在build/libs下找到war包,并移动至tomcat运行。访问localhost:8080/[war包名称]测试运行。

Idea如何使用Gradle创建并打包Springboot项目
Idea如何使用Gradle创建并打包Springboot项目

10、以上即是本篇全部内容。

© 手抄报圈