答案似乎比我想的要简单。
在您的类加载器中,将此文件夹添加到类路径(不需要jar):
/meta-INF/services/
在其中创建一个名为
javax.xml.transform.TransformerFactory
编辑它,并将其设置为以下内容:
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl
而已!
为什么行得通?请参阅Java用来加载Xalan实现的此类。
请注意,对于该特定的“ meta-
INF”条目,它似乎事实上是父后(或子优先)加载器(与常规Java类加载器的工作方式相反,例如,父先/子后)。如果我错了纠正我
摘录自 javax.xml.datatype.FactoryFinder
private static Object findJarServiceProvider(String factoryId) throws ConfigurationError { String serviceId = "meta-INF/services/" + factoryId; InputStream is = null; // First try the Context ClassLoader ClassLoader cl = ss.getContextClassLoader(); if (cl != null) { is = ss.getResourceAsStream(cl, serviceId); // If no provider found then try the current ClassLoader if (is == null) { cl = FactoryFinder.class.getClassLoader(); is = ss.getResourceAsStream(cl, serviceId); } } else { // No Context ClassLoader, try the current // ClassLoader cl = FactoryFinder.class.getClassLoader(); is = ss.getResourceAsStream(cl, serviceId); } if (is == null) { // No provider found return null; } ...


