在eclipse中执行main方法的时候,默认的XML解析类是com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl,这个是没问题的。
但是当用ant的java标签执行该main方法的时候却出了问题,例如
<target name="com.yingxia.trms.clean"> <java classname="com.yingxia.trms.clean.CleanImageFile"> <classpath refid="classpath" /> </java> </target>
原来ant执行的时候,默认的XML解析类是org.apache.xerces.jaxp.DocumentBuilderFactoryImpl,所以报了如上的错误。
解决方法,在XML解析之前,强制性的指定:
System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");