How to set Javax.xml.transform.TransformerFactory system property

笑着哭i 提交于 2020-06-27 16:01:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!