0
点赞
收藏
分享

微信扫一扫

SpringBoot遍历Lib读取引用jar包列表

陆佃 2022-05-27 阅读 58

URL url = InternationalResouces.class.getProtectionDomain().getCodeSource().getLocation();

JarFile jarFile = new JarFile(url.getFile()); Enumeration<JarEntry> enumeration = jarFile.entries(); while (enumeration.hasMoreElements()) { JarEntry entry = enumeration.nextElement(); String entryName = entry.getName(); if (entryName.indexOf(path) != -1 && entryName.endsWith("properties")) { String[] pathGroup = entryName.split("/"); String fileName = pathGroup[pathGroup.length - 1]; String[] nameGroup = fileName.split("\\."); if (nameGroup.length != 2) { continue; } String realName = nameGroup[0]; String[] realNameGroup = realName.split("_"); if (realNameGroup.length != 2) { continue; } String country = realNameGroup[1]; Properties properties = new Properties(); properties.load(jarFile.getInputStream(entry)); LanguageStore store = new LanguageStore(); store.setCountry(country); store.setLanguageMap(properties); languageStore.add(store); } } jarFile.close();

举报

相关推荐

0 条评论