Springboot jar包外指定配置文件及原理
- 解决方案:
修改maven的pom.xml文件
不拷贝资源文件
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>*</exclude>
</excludes>
<filtering>true</filtering>
</resource>
</resources>
修改打包方式
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
</configuration>
</plugin>
- 运行
假设application.properties和application-{profile}.properties都在/tmp/temp/config,jar文件在/tmp/temp
java -Dloader.path=file:///tmp/temp/config,demo-1.0.jar -jar demo-1.0.jar
- 原理
对比jar包中MANIFEST.MF文件在`ZIP配置前后的区别
配置前:
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.chinaunicom.gateway.GatewayApplication
配置后:
Main-Class: org.springframework.boot.loader.PropertiesLauncher
Start-Class: com.chinaunicom.gateway.GatewayApplication
发现是类加载器变了,查看org.springframework.boot.loader包下所有加载器实现:
查看五个类描述:官方文档
JarLauncher
Launcher for JAR based archives. This launcher assumes that dependency jars are included inside a /BOOT-INF/lib directory and that application classes are included inside a /BOOT-INF/classes directory.WarLauncher
Launcher for WAR based archives. This launcher for standard WAR archives. Supports dependencies in WEB-INF/lib as well as WEB-INF/lib-provided, classes are loaded from WEB-INF/classes.PropertiesLauncher
Launcher for archives with user-configured classpath and main class via a properties file. This model is often more flexible and more amenable to creating well-behaved OS-level services than a model based on executable jars.
Looks in various places for a properties file to extract loader settings, defaulting to application.properties either on the current classpath or in the current working directory. The name of the properties file can be changed by setting a System property loader.config.name (e.g. -Dloader.config.name=foo will look for foo.properties. If that file doesn’t exist then tries loader.config.location (with allowed prefixes classpath: and file: or any valid URL). Once that file is located turns it into Properties and extracts optional values (which can also be provided overridden as System properties in case the file doesn’t exist):
loader.path: a comma-separated list of directories (containing file resources and/or nested archives in .jar or .zip or archives) or archives to append to the classpath. BOOT-INF/classes,BOOT-INF/lib in the application archive are always used
loader.main: the main method to delegate execution to once the class loader is set up. No default, but will fall back to looking for a Start-Class in a MANIFEST.MF, if there is one in ${loader.home}/META-INF.spring-boot-maven-plugin帮助
对zip格式说明
对jar和war说明
Springboot jar包外指定配置文件及原理的更多相关文章
- 手动运行jar包,指定配置文件
打包程序 mvn package cd target 指定参数运行 java -jar spring-boot-demo-0.0.1-SNAPSHOT.jar --spring.profile.act ...
- springboot项目实现jar包外配置文件管理
背景 为实现快速搭建和开发,项目以Springboot框架搭建,springboot搭建的项目可以将项目直接打成jar包并运行,无需自己安装配置Tomcat或者其他服务器,是一种方便快捷的部署方式. ...
- Spring boot框架项目,使用maven命令将配置文件打包到jar包外,项目运行读取jar外配置文件
1.1 在eclipse中配置maven命令 Mvn -e clean package -Ptest -DskipTests=true 1.1.1 执行命令之后得到jar 1.2 ...
- 更新jar包里的配置文件
更新jar包里的配置文件 起因 从笔记本传了个jar到服务器,运行的时候才发现配置文件一个ip项填错了.本来很简单的问题,maven重新打包就可以了,但是30多M的jar包就因为一个配置项错了又要重新 ...
- 如何读取jar包外的properties文件和log4j.properties
http://jrails.iteye.com/blog/1705464 ***************************************' 一般在项目中使用properties配置文件 ...
- main函数读取jar包外部的配置文件properties
首先,Java的main方法有个初始化入参args,如下所示: public static void main(String[] args) {} 然后,在linux下执行jar包引入外部配置文件的命 ...
- 加载所有jar包下指定文件
加载所有jar包下指定文件: 如spring中加载 META-INF/spring.handlers 加载 org.springframework.core.io.support.Properties ...
- Maven引入jar包中的配置文件未被识别
我用的办法是直接将jar包中的配置文件复制出来,粘贴到我自己项目中的配置文件中,讯飞语音的jar包就有这种情况.
- XJar: Spring-Boot JAR 包加/解密工具,避免源码泄露以及反编译
XJar: Spring-Boot JAR 包加/解密工具,避免源码泄露以及反编译 <?xml version="1.0" encoding="UTF-8" ...
随机推荐
- 2019微软Power BI 每月功能更新系列——3月Power BI 新功能学习
Power BI3月产品功能更新发布啦!本次新功能新增了热图和单选切片器:完善了新的DAX功能和对现有功能的改进(例如按钮和选择窗格):同时官方表示建模视图的全面改进也正在进行中~Woo~那么,本月更 ...
- DataBase——Mysql的DataHelper
源帖 https://www.cnblogs.com/youuuu/archive/2011/06/16/2082730.html 保护原帖,尊重技术,致敬工匠! using System; usin ...
- python学习6---排序问题
1.对列表排序 一维列表: sorted():可用于任何可迭代对象,如数组.列表.字典等. sort():list.sort()返回None,这是因为sort在函数内部修改了list的值,当再次访问l ...
- 我的代码-flask
import pickleimport flaskimport pandas as pdimport jsonfrom flask import Flaskfrom flask import requ ...
- Good Time 冲刺四
---恢复内容开始--- 一.今日完成任务情况及遇到的问题 第四天 日期:2018.6.17 王怡镔:在学习工程中,逐步完善个人中心界面的设计和编写. 于鑫宇:对小程序内容进行一些修改,复习了昨天学过 ...
- antd-vue按需加载插件babel-plugin-import报错
报错.bezierEasingMixin().百度了一下是Less版本太高的原因,我都迷了,还有太新的过... 解决方法:将less版本降到3.0以下 因为我是用的npm生成的vue项目.所以cmd命 ...
- SQL Sever 2012版本数据库的完全卸载
首先再使用的过程中,遇到当前版本和项目数据库服务器的SQL Sever 版本不一致,导致无法正常的数据导入. 所以需要我们将本地的SQL Sever 数据库,进行一个完整的卸载,进而去安装和项目一致的 ...
- Ubuntu18.04下make menuconfig缺少ncurses库
kent@hu:~/work/03-kernel/linux-4.15.1$ make menuconfig *** Unable to find the ncurses libraries or t ...
- 前端小白第一次使用redux存取数据练习
在学习了redux基本教程后,课程参考如下网址:https://www.redux.org.cn/docs/introduction/CoreConcepts.html,开始着手练习 1.首先编写一个 ...
- [硬件]_ELVE_STLINK下载出现nternal command error问题
我之前也出现过这个这个,然后折腾一晚上,升级什么都都不好使 最后我换了一根短的线,回归正常!!!