1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| private static void checkManifest() throws Exception { log.info("项目根路径: {}", System.getProperty("user.dir"));
String path = ClassUtils.getDefaultClassLoader().getResource("").getPath(); log.info("classes-path1: {}", URLDecoder.decode(path, "utf-8"));
String path2 = ResourceUtils.getURL("classpath:").getPath(); log.info("classes-path2: {}", path2);
if (path.startsWith("file")) { path = path.substring(5).replace("!/BOOT-INF/classes!/", ""); } JarFile jarFile = new JarFile(path); Manifest manifest = jarFile.getManifest(); Attributes mainAttributes = manifest.getMainAttributes(); mainAttributes.forEach((key, value) -> log.info("manifest: [{}]", key + ":" + value)); mainAttributes.put(new Attributes.Name("author"), "cuishiying");
Manifests.inject("ota-site", "idea360.cn"); log.info("ota-site: {}", Manifests.read("ota-site"));
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource[] resources = resolver.getResources(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "META-INF/MANIFEST.MF"); for (Resource resource : resources) { URL manifestUrl = resource.getURL(); if ("jar".equals(manifestUrl.getProtocol()) && manifestUrl.toString().endsWith("!/META-INF/MANIFEST.MF") && !manifestUrl.toString().contains("/BOOT-INF/lib/")) { log.info("MANIFEST.MF: {}", manifestUrl); } }
Properties properties = new Properties(); properties.load(ClassUtils.getDefaultClassLoader().getResourceAsStream("xxx.properties")); log.info("自定义配置文件: {}", properties);
}
|