TransformerFactory and Xalan Dependency Conflict

后端 未结 6 1782
我寻月下人不归
我寻月下人不归 2021-01-12 21:54

I have the following code:

javax.xml.transform.TransformerFactory factory = TransformerFactory.newInstance();
factory.setAttribute(XMLConstants.ACCESS_EXTERN         


        
6条回答
  •  长情又很酷
    2021-01-12 22:55

    I was facing a similar issue where an implementation from SaxonJ was being created in TransformerFactory::newInstance, giving me errors when trying to set attributes not supported by it.

    Taking a look at the method documentation, I found out that TransformerFactory has a priority list where it tries to find an implementation to return.

    The first place it looks for is in the system properties, so in my Ant file, inside my run target, I added the following(other libraries will have the same):

    
    

    This will make TransformerFactory::newInstance load the correct factory implementation.

    Keep in mind that I was using OpenJDK8, you will have to find the correct package for other versions.

提交回复
热议问题