Java WebApp: Loading resource from .jar located in WEB-INF

Posted by shaman.sir on Stack Overflow See other posts from Stack Overflow or by shaman.sir
Published on 2010-04-06T10:40:48Z Indexed on 2010/04/06 10:43 UTC
Read the original article Hit count: 388

Filed under:
|
|
|
|

There are a lot of similar questions, but, probably, mine is a little bit different:

What is the right way to load resource from inside of .jar file located in WEB-INF/lib folder (if I know the jar file name and the name of the class it resource belongs to), while Web Application is running? Should I use getServletContext().getResourceAsStream(?) for this purpose or the <name-of-known-class>.getResourseAsStream(?), and what path do I need to specify there?

So, the structure is:

/WEB-INF
    /classes
        /some/package/name
           ?.class #some Java code or Servlet that tries to read 'required-file.xml'
    /lib
        /<jar-with-known-name>.jar
            /another/package/with/known/name
                SomeKnownClass.class
                required-file.xml

© Stack Overflow or respective owner

Related posts about java

Related posts about web-development