我在 Eclipse 插件中使用 xalan 时遇到问题。
当我尝试通过以下方式创建工厂实例时:
TransformerFactory tFactory = TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", null);
我得到错误:
javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found
...
我在插件类路径中有以下库:xml-apis.jar、xercesImpl.jar、serializer.jar、xalan.jar
我什至无法通过以下方式创建类实例:
c = Class.forName("org.apache.xalan.processor.TransformerFactoryImpl");
Object o = c.newInstance();
它返回 ClassNotFoundException
但是我可以从同一个 jar 中创建其他类的实例,并且可以在 eclipse 之外运行相同的代码而不会出现问题。
任何的想法?
编辑: TransformerFactory 实例化类(比如“class1”)是插件类路径中添加的外部库的一部分,而 xalan.jar 也在插件类路径中。如果我将这个“class1”移动到插件中,它会找到提供者并且工作正常。