Search code examples
javaeclipse-pluginxalan

Using Xalan in Eclipse plugin


I am facing problems with using xalan in eclipse plugin.
When I try to create factory instance by:

TransformerFactory tFactory = TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", null);

I get error:

javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found
...

I have following libs in plugin classpath: xml-apis.jar, xercesImpl.jar, serializer.jar, xalan.jar

I even can't create class instance by:

c = Class.forName("org.apache.xalan.processor.TransformerFactoryImpl");
Object o = c.newInstance();

It returns ClassNotFoundException

But I can create instances of other classes from same jar and can run same code outside eclipse without problem.

Any idea?

Edit: TransformerFactory instantiating class (say "class1") is part of an external library added in the plugin classpath wheras the xalan.jar is also in plugin classpath. If I move this "class1" into plugin, it finds the provider and works fine.


Solution

  • Though I have seen this problem once, but I am not very sure how i solved it.

    If you are using JDK 1.5 or above then try removing xml-apis.jar. It was needed for Java 1.4 to support XML.

    Update 1


    Ok. From your question I inferred that you are writing a eclipse plug-in. If yes, then have you added the above jars using plugin.xml->Runtime->classpath? If not try to do so. Eclipse plugin considers only its runtime->classpath entries

    Update 2


    To me it still appears as a classpath resolution issue. Though, its hard to say why its happening. For a try you can also check by changing the order of included jars in plugin.xml->Runtime->classpath.

    Hope this will help.

    PS: Since you are working on eclipse plug-in development therefore I would suggest you to go through this article Eclipse - a tale of two VMs and many classloaders.