第三方Java库是指Jar文件,Jar文件清单具有专门用于指定库版本的属性。
注意:并非所有 Jar 文件实际上都指定了版本,即使它们should.
Java内置的读取该信息的方式是使用反射,但你需要知道some库中要查询的类。哪个类/接口并不重要。
Example
public class Test {
public static void main(String[] args) {
printVersion(org.apache.http.client.HttpClient.class);
printVersion(com.fasterxml.jackson.databind.ObjectMapper.class);
printVersion(com.google.gson.Gson.class);
}
public static void printVersion(Class<?> clazz) {
Package p = clazz.getPackage();
System.out.printf("%s%n Title: %s%n Version: %s%n Vendor: %s%n",
clazz.getName(),
p.getImplementationTitle(),
p.getImplementationVersion(),
p.getImplementationVendor());
}
}
Output
org.apache.http.client.HttpClient
Title: HttpComponents Apache HttpClient
Version: 4.3.6
Vendor: The Apache Software Foundation
com.fasterxml.jackson.databind.ObjectMapper
Title: jackson-databind
Version: 2.7.0
Vendor: FasterXML
com.google.gson.Gson
Title: null
Version: null
Vendor: null
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)