本文讲解在idea开发工具编辑器中如何将java项目/springboot/springmvc项目打包成jar包
1、指定环境
application.properties 指定打包时候用哪个配置文件
spring.profiles.active=prod
开发环境配置文件:
application-dev.properties
spring.profiles.active=prod
spring.application.name=demo
server.port=8099
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/templates/,classpath:/static/
spring.datasource.username=abc
spring.datasource.password=abc
spring.datasource.url=jdbc:mysql://localhost:3306/abc?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
# 自定义配置
HOST=http://abc.com
application-prod.properties
2、新增maven打包配置
点击Idea右上角run左边的环境
选择Edit Configurations
打开Run/Debug Configurations窗口
点击左上角+,新增maven,运行命令填写如下
clean compile package -Dmaven.test.skip=true
3、运行maven打包,生成jar包
D:\BaiduNetdiskDownload\a1\demo\target
4、运行
demo-0.0.1-SNAPSHOT.jar 在 pom.xml里面配置
java -jre D:\BaiduNetdiskDownload\a1\demo\target\demo-0.0.1-SNAPSHOT.jar