Java and XML Basics, Part 1 - Appendix: Installing Xerces-J 2.0.0 under JDK 1.4
(Page 5 of 5 )
As stated above, just by loading XercesJ into the class path doesn't solve the problem, as both Crimson and XercesJ are JAXP compliant, and the javax.xml.parsers factories, when loaded, will load the first JAXP provider found which is always Crimson (as this is included in the rt.jar runtime jar). In order to allow XercesJ to "override" Crimson, you’ll have to use the Java Endorsed API mechanism--this means creating a directory (the recommended method is to create it in your <JAVA_HOME>\lib directory and call it "endorsed"--therefore the full path would be <JAVA_HOME>\lib\endorsed) and in the command line that starts the Java interpreter add the following option:
-Djava.endorsed.dirs=<JAVA_HOME>\lib\endorsed
(Or the path to the directory where you have placed the XercesJ jars.) If you have more than one directory, you can separate them with “;” on Windows or “:” or UNIX. This will allow the Java interpreter, when starting up, to load the JAXP API providers form this directory first, and therefore the XercesJ classes will be loaded rather than Crimson. One easy way to test it is with the following code:
import javax
.xml.parsers.*;
....
/*** Checkout the parser ***/
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
System.out.println( "Factory: " + dbf );
DocumentBuilder db = dbf.newDocumentBuilder();
System.out.println( "Builder: " + db );
/***/
....
If the output shows a class name in the package
org.apache.xerces.jaxp... then
Xerces is loaded, otherwise, you should check your class path, endorsed API path and make sure that it's all set correctly for
XercesJ to load.
Finally, you can download the support files here.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |