How do I find out which JAXP implementation is in use and where it was loaded from?

后端 未结 5 633
渐次进展
渐次进展 2020-12-02 10:11

I would like to provide diagnostic information about what JAXP implementation is in use, and which JAR file it was loaded from.

One way to achieve this is to create

5条回答
  •  感动是毒
    2020-12-02 10:32

    It depends, but generally no.

    DocumentBuilderFactory.newInstance() will either return the implementation of DocumentBuilderFactory which is configured in the system property "javax.xml.parsers.DocumentBuilderFactory" or the JRE's default factory if the system property is not set. The default factory is most likely hard coded in the implementation of the newInstance method and not otherwise accessible.

    If the system property is set, you could at least use the getResource method on the relevant class loader to get the URL, from which the class loader would load the corresponding class file. If it is from a jar file, you should be able to extract the file name (or source URL) from the jar: URL. Detailed package information should also be available if you manaully read the meta data files from the classpath.

    If the system property is not set, I'm pretty sure that you have no way to get the information you are looking for without actually creating a new factory as you're already doing.

提交回复
热议问题