Tag: 诊断

如何找出正在使用的JAXP实现以及从哪里加载?

我想提供有关正在使用的JAXP实现以及从中加载的JAR文件的诊断信息。 实现此目的的一种方法是在例如DocumentBuilderFactory实例中创建,然后检查该类的属性: private static String GetJaxpImplementation() { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); Class 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 ?