Hi Richard,

Ini.fromResourcePath will work with "classpath:foo.ini" if and only if
foo.ini is at the root of the classpath.  /WEB-INF is not the root of
the classpath.  /WEB-INF/classes is at the root of the classpath
however, so you could put your file in there if you wanted.

Loading directly from /WEB-INF/* is a servlet-container specific thing
- the Ini class does not know how to do this since that would impose
cross-cutting concerns on the Ini class (to know about
Servlet-specific behavior).  Loading resources from /*WEB-INF/* is a
web-module-specific behavior achieved by loading an input stream via
servletContext.getResourceAsStream(pathRelativeToTheWebInfDirectory);

The WebIniEnvironment's 'convertPathToIni' method will check for a
file under /WEB-INF/ if and only if there isn't already a scheme
qualifier (classpath:, file:, or url:).

HTH,
--
Les Hazlewood | @lhazlewood
CTO, Stormpath | http://stormpath.com | @goStormpath | 888.391.5282


On Mon, Jun 3, 2013 at 2:50 PM, [email protected]
<[email protected]> wrote:
> I am trying to read an INI file from the same location as the default
> shiro.ini (either "/WEB-INF/shiro.ini" or "classpath:shiro.ini").
>
> The obvious approach fails:
> Ini ini = Ini.fromResourcePath(location);
>
> This fails even when location is set to the existing default shiro.ini as
> either "/WEB-INF/shiro.ini" or "classpath:shiro.ini".  The errors are
> similar to these (running in Jetty on Windows):
> java.io.FileNotFoundException: \WEB-INF\shiro.ini (The system cannot find
> the path specified)
> java.io.IOException: Resource [classpath:shiro.ini] could not be found.
>
> If I specify a full path on my system
> ("/User/.../src/main/webapp/WEB-INF/shiro.ini"), this succeeds, but is
> impractical in a deployed application.  Is there some special magic I am
> missing to get the classpath or something else to work properly?  Or is
> there a better way of reading an INI file?
>
> I did take a look at how the IniWebEnvironment class does this, but that
> does not seem to be generalizable, as implied by certain TODOs there.
>
> (This is tangentially related to my previous question.)
>
> Thanks.
>
>
>
> --
> View this message in context: 
> http://shiro-user.582556.n2.nabble.com/How-to-read-an-INI-file-on-the-classpath-tp7578796.html
> Sent from the Shiro User mailing list archive at Nabble.com.

Reply via email to