The standard configuration of JAXP can be changed in several ways. Because they are not all well known, they will be explained in the following sections using Xerces and Xalan.
The Java runtime reads the following environment variables and tries to load their values as classes:
"javax.xml.parsers.DocumentBuilderFactory" "javax.xml.parsers.SAXParserFactory" "javax.xml.transform.TransformerFactory"
These properties can be set in different ways, which are shown by the following numbered sections. If a configuration option can override another, the one with the higher is described first.
The JAXP properties can be set directly in a program:
System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl"); System.setProperty("javax.xml.transform.TransformerFactory", "org.apache.xalan.processor.TransformerFactoryImpl");
A configuration parameter for the Java process to be started can be set
using the flag for system properties -D
in combination with
the special environment variable _JAVA_OPTIONS
.
The next example shows one of the three JAXP properties, but of course
all three are possible:
set _JAVA_OPTIONS=-Djavax.xml.transform.TransformerFactory= org.apache.xalan.processor.TransformerFactoryImpl
The configuration with the start option -D
can also be
placed in the special environment variable JAVA_TOOL_OPTIONS
.
This variable is evaluated by some JDK implementations.
The next example shows this option again with only one property:
set JAVA_TOOL_OPTIONS=-Djavax.xml.transform.TransformerFactory= org.apache.xalan.processor.TransformerFactoryImpl
The JAXP configuration can also be placed in the file jaxp.properties
in the folder JAVA_HOME/jre/lib
:
# # Sample configuration, file %JAVA_HOME%\jre\lib\jaxp.properties. # # Defaults in Java 1.7.0, Windows: # #javax.xml.parsers.DocumentBuilderFactory = \ com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl #javax.xml.parsers.SAXParserFactory = \ com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl #javax.xml.transform.TransformerFactory = \ com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl # # Values for Xerces and Xalan: # javax.xml.parsers.DocumentBuilderFactory = \ org.apache.xerces.jaxp.DocumentBuilderFactoryImpl javax.xml.parsers.SAXParserFactory = \ org.apache.xerces.jaxp.SAXParserFactoryImpl javax.xml.transform.TransformerFactory = \ org.apache.xalan.processor.TransformerFactoryImpl
And a special technique for ANT is to use the environment variable ANT_OPTS
:
set ANT_OPTS=-Djavax.xml.transform.TransformerFactory= org.apache.xalan.processor.TransformerFactoryImpl set ANT_OPTS=-Djavax.xml.parsers.DocumentBuilderFactory= org.apache.xerces.jaxp.DocumentBuilderFactoryImpl set ANT_OPTS=-Djavax.xml.parsers.SAXParserFactory= org.apache.xerces.jaxp.SAXParserFactoryImpl
The declared XML and XSLT classes have to be found in the classpath or
in the folder JAVA_HOME\jre\lib\ext
. This last option is not
recommended because only a few developers know about it. In case you
are debugging a strange problem, you would not think to look at the
version of the JAR's in that folder.
Note that Eclipse reads all existing environment variables only at startup and does not change anything later.