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

陆佃

关注

阅读 60

2022-05-27

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)

0 0 举报