Load my own Xalan implementation where an older Xalan is loaded to the parent classloader

前端 未结 2 1878
北恋
北恋 2021-01-27 12:22

I\'m writing a plugin for a framework that loads my code as a child classloader

The problem is that that framework uses a certain Xerces version, that is not compatible

相关标签:
2条回答
  • 2021-01-27 12:38

    Have you tried loading the classes of your framework and Xerces libs as a part of the ExtClassLoader by placing them in path corresponding to the java.ext.dirs system property? This way the framework's version of Xerces implementation will be loaded by the ExtClassLoader.

    You can then place your version of Xerces implementation in the path corresponding to the java.class.path system property to be loaded by the AppClassLoader.

    I have not tried this myself, but considering the class loading hierarchy this should work. You can learn more about the class loading hierarchy here - http://onjava.com/pub/a/onjava/2005/01/26/classloading.html

    0 讨论(0)
  • 2021-01-27 12:44

    try doing:

    ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(childClassLoader);
    try{
        // do xml parsing
    }finally{
        Thread.currentThread().setContextClassLoader(oldContextClassLoader);
    }
    
    0 讨论(0)
提交回复
热议问题