users@glassfish.java.net

Re: java.io.FileNotFoundException tried to access a xml file with jdom

From: <Jan.Luehe_at_Sun.COM>
Date: Sun, 12 Aug 2007 12:34:16 -0700

glassfish_at_javadesktop.org wrote:

>Thanks for your reply!
>
>i've found another way without the serverlet context. look this:
>
>[b]ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
>InputSource is = new InputSource(classLoader.getResourceAsStream("menu.xml"));
>Document doc=builder.build(is);[/b]
>
>

Notice that retrieving webapp resources via the webapp's WebappClassLoader,
which is what Thread.currentThread().getContextClassLoader() returns,
will not be a complete solution.

WebappClassLoader.getResource[AsStream]() considers only resources
located in
WEB-INF/classes and WEB-INF/lib/[*.jar|*.zip].

In order to retrieve any resources outside of WEB-INF/classes and
WEB-INF/lib/[*.jar|*.zip], you need to use
ServletContext.getResource[AsStream]().


Jan