users@glassfish.java.net

Re: load properties file in a war context

From: <Jan.Luehe_at_Sun.COM>
Date: Tue, 04 Sep 2007 15:30:24 -0700

glassfish_at_javadesktop.org wrote:

>Probably a trivial subject, but...
>
>In a war application I try to load some properties files (for logging, ...) in a contained jar.
>
>then I tried several solution and didn't succeed to have some beautiful way to have this working.
>in my war structure, my properties files (and my jar library trying to load them) are in :
>WEB-INF/lib
>
>According to glassfish documentation, this path is included in class loading path for a web context application.
>
>but with :
>- getClass().getClassLoader().getResourceAsStream() it doesn't work
>- Thread.currentThread().getContextClassLoader().getResourceAsStream() it doesn't work
>
>

No sure I follow your exact scenario, but if your "myfile.properties" is
bundled
in a JAR file located under WEB-INF/lib, then accessing it from a servlet,
using either of the above approaches, e.g.,

  getClass().getClassLoader().getResourceAsStream("myfile.properties")

will work. I just tried it myself.


Jan