我们使用 maven 打包出来的 jar包,如何在jar包内部获取自身的版本号?
try {
Enumeration<URL> resources = Version.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
Manifest manifest = new Manifest(resources.nextElement().openStream());
Attributes attrs = manifest.getMainAttributes();
if (attrs == null) {
continue;
}
String name = attrs.getValue("Bundle-Name");
if (name != null && name.equals("Redisson")) {
log.info("Redisson " + attrs.getValue("Bundle-Version"));
break;
}
}
} catch (Exception E) {
// skip it
}
网友评论