我想提供有關正在使用哪些JAXP實現以及從哪個JAR文件加載的診斷信息。實現這一如何找出正在使用哪個JAXP實現以及它從哪裏加載?
一種方法是在實例創建,例如,DocumentBuilderFactory
,然後檢查該類別的屬性:無需
private static String GetJaxpImplementation() {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
Class<? extends DocumentBuilderFactory> c = documentBuilderFactory.getClass();
Package p = c.getPackage();
CodeSource source = c.getProtectionDomain().getCodeSource();
return MessageFormat.format(
"Using JAXP implementation ''{0}'' ({1}) version {2} ({3}){4}",
p.getName(),
p.getImplementationVendor(),
p.getSpecificationVersion(),
p.getImplementationVersion(),
source == null ? "." : " loaded from: " + source.getLocation());
}
有沒有更好的方式來實現這一目標,也許創建一個DocumentBuilderFactory
?
這是自8u40是BTW過時,你可以檢查它是否仍與'使用-XX:+ CheckEndorsedAndExtDirs'。 – eckes 2016-10-31 16:46:22