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" ...
随机推荐
- JAVA003-变量、数据类型
一.变量的三个元素:变量名(房间名字).变量类型(房间的类型).变量值(入住的人). 二.变量的命名规则: 1.驼峰法 2.尽量简单,见名知意 3.长度没有限制 4.满足标志符 ...
- 《xxx系统》可用性与易用性功能增加
可用性:1. 用户删除的表单信息还可以进行恢复: 2. 用户可根据某一字段的某部分文字进行模糊查询. 3. 任何界面响应时间不超过5秒. 易用性:1. 审核人员进入系统后,提醒审核人进行密码修改 2. ...
- ISAPI筛选器及对ASP源文件的保护
ISAPI筛选器及对ASP源文件的保护 2009-04-21 01:45:57 标签:ISAPI 筛选器 ASP 源文件 保护 摘要:本文介绍了利用ISAPI筛选器保护ASP源文件的方法,并给出一个实 ...
- nodejs之mock与跨域代理的三两事
emmm...好久没写博客了,都忘了该怎么开始. 那就先说下mockjs.因为一些原因,导致后台接口没有数据,那么我们就开始自己造数据,使用的是比较流行mockjs,根据文档就能简单的配置,然后开始愉 ...
- storm入门基础实例(无可靠性保证实例)
本实例为入门篇无可靠性保证实例,关于storm的介绍,以及一些术语名词等,可以参考Storm介绍(一).Storm介绍(二). 本案例是基于storm0.9.3版本 1.案例结构 案例:Word Co ...
- 常用的JSP内置对象(1)
常用的JSP内置对象 request对象主要用于处理客户端请求 request对象的作用是与客户端交互,收集客户端的Form.Cookies.超链接,或者收集服务器端的环境变量. request对象常 ...
- Dictionary用法
https://www.cgjoy.com/thread-106639-1-1.html 1.新建字典,添加元素 dictionary<string,string>dic=newdict ...
- Codeforces 977D: Divide by three, multiply by two(暴力)
题意 有nnn个无序的数,对这些数进行排列,要求ai=3×ai+1a_i=3\times a_{i+1}ai=3×ai+1或2×ai=ai+12\times a_i=a_{i+1}2×ai=ai ...
- 1040 mysql Too many connections
笔者在项目中遇到mysql 出现:1040 too many connections 异常,意思是超过数据库最大连接数,打不开表结构信息.笔者排除问题建议:1.查看程序代码是否存在BUG:2.检查代码 ...
- 20164322韩玉婷 -----EXP4 恶意代码分析
1.实践目标 1.1是监控你自己系统的运行状态,看有没有可疑的程序在运行. 1.2是分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或sysinternals,sys ...