1 Reply Latest reply on Jul 24, 2013 6:57 AM by cybro

    JBoss AS 6 - load resource from WAR file

    cybro Newbie

      I am loading resources from a WAR file via



      which works pretty well under JBoss 4.2.x, but under JBoss 6 the same line doesn't work.

      JBoss 6 returns a BaseClassLoader, while JBoss 4.2.x returned a WebappClassLoader, and the BaseClassLoader doesn't seem to be the ClassLoader instance that loaded the WAR file.


      Also, is there ANY documentation on this topic? General JBoss 6 ClassLoading and/or configuration possibilities? Otherwise I'm going to have to debug JBoss just in order to have a slight chance to understand whats going actually wrong..


      Any help or hints would be greatly appreciated.


      Thanks in advance,




      P.S: Already posted at stackoverflow.com: http://stackoverflow.com/questions/17788760/load-non-java-resource-from-war

        • 1. Re: JBoss AS 6 - load resource from WAR file
          cybro Newbie

          Ok, it seems I've really been missing crucial understanding of how WAR files are structured, and supposed to work.


          When a WAR is loaded by the classloader, only the WARs "/WEB-INF/classes" and "/WEB-INF/lib" are added to the loaders classpath, but NOT the root.

          That is what made the difference between JBoss 4.2.x and 6.x - the older versions of JBoss (pre 5.x) didn't hold to that convention, and put the WARs root directory on the classpath.


          So, to provide a quick fix, just add some double dots to your path and be happy: "path/file.txt" -> "../../path/file.txt"

          You could also move the resources to your SRC directory, so they get moved to WEB-INF/classes, or modify your build process to get it from somewhere else.