Search code examples
javaxalanendorsed

How can two programs depending on different Xalan implementation coexist in the same VM / System Classloader?


I asked this question in several flavors, and I think I'm not asking the right question. I'm suspecting now that Xalan, since it's implementing a Java endorsed standard, can only have one implementation at a given VM / ClassLoader.

So is it true? can't 2 Xalan implementaions "live" in the same System ClassLoader? Or if they can, How?


Solution

  • This seems to be the surprising answer:

    For each Xalan implementation use a seperate classloader, and add a file in

    META-INF\services\ called

    javax.xml.transform.TransformerFactory
    

    Edit it and put it's only content the Xalan implementation the class loader will use, e.g.:

    com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl
    

    NOTE: The nice thing here is that as opposed to the regular class loading delegation, META-INF\services is being searched in the current class loader first, where as classes are being search in the parent, then system, and only then in the child classloder