The way I'm getting around the issue is by calling

String root = getServletContext().getRealPath("/");

after the server has initialized (i.e. outside ServiceImpl.java's
constructor). Apparently you simply cannot get the ServletContext in
the constructor of ServiceImpl? I suppose that makes sense.

On Jan 3, 1:29 pm, ky <[email protected]> wrote:
> Just to reiterate, I would like best to find a way to obtain the base
> path for the web application that lives inside the war.
>
> @Lothar:
>
> Thanks for the tip; I am calling getClass().getResourceAsStream
> ("config.txt") from ServiceImpl.java in the server package. It works
> when I put config.txt in the server package, but I was hoping to put
> it in the war in the same place as the main .html file, on the same
> level where /WEB-INF resides. If I try getClass().getResourceAsStream
> ("/config.txt") however, I get a null. Any idea what I might be doing
> wrong?
>
> @Mariyan:
>
> This is a file that the server needs to load that the client knows
> nothing about. I am new to java web application development though, so
> I am open to suggestions about best practices. I've read about
> properties files in XML that reside on the server but I can't find how
> to set them up. I suppose I could manually add a property for the
> correct path if I can't programatically determine it.
>
> On Jan 3, 5:38 am, Lothar Kimmeringer <[email protected]> wrote:
>
> > ky schrieb:
>
> > > I am trying to have the server read from a file, called "config.txt",
> > > in the same directory as the main .html file within the war.
>
> > > In hosted mode, I can easily access the file using a Scanner object:
>
> > > Scanner s = new Scanner("config.txt");
>
> > > But this does not work when deployed because the file paths are
> > > somehow different. How can I get the correct file path to access
> > > config.txt in the deployed version?
>
> > getClass().getResourceAsStream("/config.txt");
> > It returns null if the file can't be found. if you place the
> > config-file in the same package as the class reading it, you
> > can leave away the slash.
>
> > Regards, Lothar

--

You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.


Reply via email to