DocumentBuilderFactory以及SAXParserFactory具体实现的查找步骤

原文地址: http://ephon.spaces.live.com/blog/cns!796FAD06E2C0A525!589.entry

JAXP DocumentBuilderFactory 以及 SAXParserFactory 具体实现的查找步骤
1、使用"javax.xml.parsers.DocumentBuilderFactory"系统属性。 即使用Java -Djavax.xml.parsers.DocumentBuilderFactory=.. ..定义的系统属性,可以通过System.getProperty("javax.xml.parsers.DocumentBuilderFactory")获得;
2、使用"jre\lib"下面的jaxp.properties 文件中键值为 javax.xml.parsers.DocumentBuilderFactory属性获得;
3、使用运行时类路径中JAR包中的"META-INF/services/javax.xml.parsers.DocumentBuilderFactory"文件中的第一行的内容作为具体的Factor实现;
同样了,对于寻找javax.xml.parsers.SAXParserFactory的过程与上述相同,只不过,属性名称为"javax.xml.parsers.SAXParserFactory"。
对于sun的jre来说,如果上述的三个地方均找不到,那么:
对于javax.xml.parsers.DocumentBuilderFactory: sun提供默认实现:com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl 对于javax.xml.parsers.SAXParserFactory: sun提供默认实现:com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl


另外,Trouble-shooting的好工具:
请设置属性 -Djaxp.debug=1,系统会把寻找javax.xml.parsers.DocumentBuilderFactory和javax.xml.parsers.SAXParserFactory 的具体过程给打印出来。就像下面:
JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl using ClassLoader: sun.misc.Launcher$AppClassLoader@7259da
JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory
JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl

.........

JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory
JAXP: found jar resource=META-INF/services/javax.xml.parsers.DocumentBuilderFactory using ClassLoader: nc.bs.mw.start.BootstrapClassLoader@e5b723
JAXP: found in resource, value=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl
JAXP: created new instance of class org.apache.xerces.jaxp.DocumentBuilderFactoryImpl using ClassLoader: nc.bs.mw.start.BootstrapClassLoader@e5b723
JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory
JAXP: found jar resource=META-INF/services/javax.xml.parsers.DocumentBuilderFactory using ClassLoader: nc.bs.mw.start.BootstrapClassLoader@e5b723

.........

JAXP: find factoryId =javax.xml.parsers.DocumentBuilderFactory
JAXP: found jar resource=META-INF/services/javax.xml.parsers.DocumentBuilderFactory using ClassLoader: WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
nc.bs.mw.start.BootstrapClassLoader@e5b723

.........

你可能感兴趣的:(apache,eclipse,jdk,xml,sun)