#springboot --使用profiles管理在IntelliJ IDEA编译器中可以运行,打成jar包无法切换到被激活文件导致无法运行的解决办法

本文介绍在SpringBoot项目中,如何通过profiles分区管理实现开发环境与生产环境的切换,特别是在打包成jar后,如何通过命令行参数--spring.profiles.active激活指定配置文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

通常,在spirngboot框架中,我们使用profiles分区管理进行开发环境和生产环境的切换,我们可以通过一个名为spring.profiles.active=xxx来激活某个分区的资源文件,但有时也会造成打成jar包后无法切换到被激活文件导致无法运行(在编译器中可以运行),解决方法如下所示。
在java -jar xxx-0.0.1-SNAPSHOT.jar命令后强制添加–spring.profiles.active=yyy,这样在jar包环境下,就会激活名为application-yyy的yml或资源文件。

D:\Java\bin\java.exe -Dmaven.multiModuleProjectDirectory=C:\Users\yangj\Desktop\huiyiguanlixitong -Djansi.passthrough=true "-Dmaven.home=D:\java\idea\IntelliJ IDEA 2024.3.1.1\plugins\maven\lib\maven3" "-Dclassworlds.conf=D:\java\idea\IntelliJ IDEA 2024.3.1.1\plugins\maven\lib\maven3\bin\m2.conf" "-Dmaven.ext.class.path=D:\java\idea\IntelliJ IDEA 2024.3.1.1\plugins\maven\lib\maven-event-listener.jar" "-javaagent:D:\java\idea\IntelliJ IDEA 2024.3.1.1\lib\idea_rt.jar=64647:D:\java\idea\IntelliJ IDEA 2024.3.1.1\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "D:\java\idea\IntelliJ IDEA 2024.3.1.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.8.0.jar;D:\java\idea\IntelliJ IDEA 2024.3.1.1\plugins\maven\lib\maven3\boot\plexus-classworlds.license" org.codehaus.classworlds.Launcher -Didea.version=2024.3.1.1 -s D:\apache-maven-3.6.3\conf\settings.xml [INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for com.jlwl:huiyiguanlixitong:war:1.0-SNAPSHOT [WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 286, column 21 [WARNING] [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. [WARNING] [WARNING] For this reason, future Maven versions might no longer support building such malformed projects. [WARNING] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.073 s [INFO] Finished at: 2025-05-12T10:28:31+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available
05-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值