问题
I am using javax.xml.transform.Transform to convert an xml file to a PDF. This works fine on its own, but some part of the project is using Xalan, which implements its own TransformerFactory, and something in there doesn't work with Cyrillic.
I have found at https://xml.apache.org/xalan-j/usagepatterns.html that there is a property which is used to define the used factory :
TransformerFactory is an abstract class with a static newInstance() method that instantiates the concrete subclass designated by the javax.xml.transform.TransformerFactory system property.
The default setting for this system property is org.apache.xalan.processor.TransformerFactoryImpl.
My question is : How do I set this property to not use Xalan ?
回答1:
Either set it statically from the command line when you execute your program, using the -D
flag:
java -Dorg.apache.xalan.processor.TransformerFactoryImpl=com.xyz.YourFactory YourApp
Or dynamically from within your application, using System.setProperty():
System.setProperty("org.apache.xalan.processor.TransformerFactoryImpl",
"com.xyz.YourFactory");
Note that you need to use the fully qualified class name of the factory class, and that the factory needs to be on your classpath for either of these to work.
回答2:
Try to set it as a java argument -Djavax.xml.transform.TransformerFactory=<factory class>
You can also intantiate the desired factory directly in your program as TransformerFactory tf = new SomeTransformerFactoryImpl();
来源:https://stackoverflow.com/questions/53629927/how-to-set-javax-xml-transform-transformerfactory-system-property