开发者

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

开发者 https://www.devze.com 2023-02-19 20:25 出处:网络
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 implement

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 s开发者_开发百科ame System ClassLoader? Or if they can, How?


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


There is some xalan version included in the jdk. For most usages, my personal experience is that using this version is enough. Even if it could be a previous version, is there any new xalan development nowadays? I prefer using the included, strongly tested version.

I don't think having to xsl transformers in the same jdk is a good idea (even if I guess it can be done). If you really need to use some updated version of xalan, instead of the jdk one, you could referer to this faq: http://xml.apache.org/xalan-j/faq.html#faq-N100EF

I stripped all specific xalan dependencies in big applications, using just the embedded one. Libraries as FOP, although they previously pretended to require some specific xalan jar, ran just fine without it, and it solved a lot of class loading issues (java ee app server giving problems in some situations when xalan was packaged).

0

精彩评论

暂无评论...
验证码 换一张
取 消