加载所有jar包下指定文件
加载所有jar包下指定文件:
如spring中加载 META-INF/spring.handlers 加载
org.springframework.core.io.support.PropertiesLoaderUtils#loadAllProperties(java.lang.String, java.lang.ClassLoader)
/**
* Load all properties from the specified class path resource
* (in ISO-8859-1 encoding), using the given class loader.
* <p>Merges properties if more than one resource of the same name
* found in the class path.
* @param resourceName the name of the class path resource
* @param classLoader the ClassLoader to use for loading
* (or {@code null} to use the default class loader)
* @return the populated Properties instance
* @throws IOException if loading failed
*/
public static Properties loadAllProperties(String resourceName, @Nullable ClassLoader classLoader) throws IOException {
Assert.notNull(resourceName, "Resource name must not be null");
ClassLoader classLoaderToUse = classLoader;
if (classLoaderToUse == null) {
classLoaderToUse = ClassUtils.getDefaultClassLoader();
}
Enumeration<URL> urls = (classLoaderToUse != null ? classLoaderToUse.getResources(resourceName) :
ClassLoader.getSystemResources(resourceName));
Properties props = new Properties();
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
URLConnection con = url.openConnection();
ResourceUtils.useCachesIfNecessary(con);
InputStream is = con.getInputStream();
try {
if (resourceName.endsWith(XML_FILE_EXTENSION)) {
props.loadFromXML(is);
}
else {
props.load(is);
}
}
finally {
is.close();
}
}
return props;
}
事例:
public static void main(String[] args) {
String handlerMappingsLocation = "META-INF/spring.handlers";
try {
Properties properties = PropertiesLoaderUtils.loadAllProperties(handlerMappingsLocation, BeanUtil.class.getClassLoader());
Enumeration<?> enumeration = properties.propertyNames();
while (enumeration.hasMoreElements()) {
String key = (String) enumeration.nextElement();
System.out.println(key);
}
} catch (IOException e) {
e.printStackTrace();
}
}
核心语法:
ClassLoader.getSystemResources(resourceName)
加载所有jar包下指定文件的更多相关文章
- Spark on Yarn运行时加载的jar包
spark on yarn运行时会加载的jar包有如下: spark-submit中指定的--jars $SPARK_HOME/jars下的jar包 yarn提供的jar包 spark-submit通 ...
- 自定义ClassLoader,用于加载用户JAR包
最近在考虑C/S结构程序的软件自动升级的实现方式,比如QQ.飞信等都自动升级的功能. 自动升级模块虽然还没有编码完成,但是思路还是比较清晰的. 自动升级过程中,升级文件的JAR包是专门加载到程序中去的 ...
- 服务器程序动态加载自定义jar包的过程
需求: 用过hive的都知道,可以自定义hive的一个udf jar,然后将这个jar add到hive服务端,就会加载这个jar实现用户自定义逻辑.现在的需求就是实现这么一个服务端所做的事情! 场景 ...
- (转)自定义ClassLoader ----可以加载第三方jar包
package com.classloader.util; import java.io.IOException; import java.net.MalformedURLException; imp ...
- maven加载本地jar包到repository
maven加载本地jar到repository 这是一个常见场景,此处以本地opencv jar文件导入repository为例 1.Ubuntu下 mvn install:install-file ...
- 27 Java动态加载第三方jar包中的类
我加载的方法是://参数fileName是jar包的路径,processorName 是业务类的包名+类名public static A load(String fileName, String pr ...
- maven无法加载本地jar包以及maven项目打包后本地jar包没有打进项目的问题解决办法
1.首先设置依赖项,这样maven就会把该路径下的jar包导入项目引用 <dependency> <groupId>DPSDK-Manager</groupId> ...
- Gradle加载本地jar包
有时,我们需要的jar包不一定能在远程仓库中找到,这时我们需要加载本地的jar包. 加载单独的jar包 在项目底下添加libs目录,将jar包仍进libs目录 build.gradle配置如下: de ...
- 关于用wkwebview加载沙盒documents下html文件 模拟器可以,真机不行的解决方案
最近也遇到这个问题,把我解决的思路记录一下 1.问题: 用wkwebview加载(loadRequest)沙盒documents下html文件 模拟器可以,真机不行 (前提是html内部含引用外联样式 ...
随机推荐
- Yahoo Programming Contest 2019.F.Pass(DP)
题目链接 惊了这是什么F题...怎么我都能做出来...以后atcoder的比赛也不能走神了万一有个这样的F呢(CF已有多次了= =) \(f[i][j]\)表示Takahashi现在一共有\(i\)个 ...
- 英语口语练习系列-C27-艺术品-辨别物体-黄昏的歌
艺术品 a work of art Theory talent art gallery draw the sketch motivate students' interest full of imag ...
- [BZOJ5064]B-number
[BZOJ5064]B-number 题目大意: 求\(1\sim n(n\le10^{15})\)间有多少数满足是\(13\)的倍数且包含字符串\(13\). 思路: 数位DP.\(f[i][j][ ...
- Scrapy 使用CrawlSpider整站抓取文章内容实现
刚接触Scrapy框架,不是很熟悉,之前用webdriver+selenium实现过头条的抓取,但是感觉对于整站抓取,之前的这种用无GUI的浏览器方式,效率不够高,所以尝试用CrawlSpider来实 ...
- oracle 占比函数
这个函数在oracle帮助文档的位置:SQL Reference里面,很好找的. 除报告详细数据外,许多报告中还包括每行总数的百分比.例如,每名客户的订单相对于总订单的百分比,或每位销售代表的销售额相 ...
- JS_高程5.引用类型(5)Array类型的操作方法
一.操作方法 1.concat()方法 基于当前数组中的所有项创建一个新数组.具体说,是先创建当前数组的一个副本,然后将接收到的参数添加到这个副本的末尾,最后返回新构建的数组.在没有给concat() ...
- 增加tomcat的运行速度
1.增加tomcat的运行速度
- Linux配置防火墙,开启80端口、3306端口
Linux配置防火墙,开启80端口.3306端口 起因是因为想使用Navicat连接一下数据库,发现连接不上 通过查阅许多资料和多次测试发现是因为防火墙没有配置3306端口 话不多说,开整,同理, ...
- Windows下NetBeans中文乱码解决办法
找到你的Netbeans安装目录下的etc文件夹,用记事本打开netbeans.conf,找到netbeans_default_options(不是最后那个带句号的…), 在其属性的最后(冒号以内)加 ...
- iOS链接库的冲突
最近在打包的时候,遇到一个坑.特此记录一下 起因是发现 Unity 5.4 版本,使用c#写的下载,下载速度无法突破 2M/s,同样的网络,后来横向对比使用原来 Cocos2d 开始的游戏,可以达到 ...