0 Replies Latest reply on Oct 12, 2015 7:43 AM by Brajendra Singh

    Thread.currentThread().getContextClassLoader().getResource("/lib/") returning null

    Brajendra Singh Newbie


      We are upgrading JBoss 4.3 to JBoss AS 7 and facing this issue i.e. Thread.currentThread().getContextClassLoader().getResource("../lib/") returning null while loading resources.


      In JBoss 4.3 Thread.currentThread().getContextClassLoader().getResource("../lib/") was returning proper URL.


      With jboss-eap-6.4 we tried below approaches to load resources using Thread.currentThread().getContextClassLoader() class loader:


      1. Tried to load resource by providing WEB-INF directory as Thread.currentThread().getContextClassLoader().getResource("WEB-INF"); but it also return null;
      2. Tried to load file hibernate.cfg.xml (this file is placed under WEB-INF/classes) as Thread.currentThread().getContextClassLoader().getResource("hibernate.cfg.xml "); file loaded and can get file path as well.
      3. Tried to load any property file like abcd. properties file (this file is placed under WEB-INF/lib folder) as Thread.currentThread().getContextClassLoader().getResource("abcd. properties "); but it also return null.
      4. We also tried to load the current directory by  Thread.currentThread().getContextClassLoader().getResource("/") it is pointing to $EAP_HOMNE/modules/sun/jdk/main/service-loader-resources/

      As per our understanding it is happing because of class loader change in JBoss AS 7. In JBoss 4.3 WebappClassLoader was used and it was loading resources from ../lib directory properly but in JBoss AS 7 class loader changed to ModuleClassLoader due to this resource loading behavior got changed.


      So we have below few queries pls provide:

      1. Is there any alternate way load resources from WEB-INF/lib directory?
      2. Is there any alternate way load resources from WE-INF directory?
      3. Is there any way to load resources from *.war directory?