ky.
ky.

Reputation: 53

GWT: Reading a file from the server at server's startup

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?

I have tried getServletContext.getRealPath("config.txt"), but for some reason I get a Null Pointer Exception when I attempt to call this in the ServiceImpl's constructor...

Upvotes: 3

Views: 1460

Answers (1)

ky.
ky.

Reputation: 53

It seems like getServletContext.getRealPath("/") is the way to go, but you just can't call the method within the constructor of the server implementation.

The way I eventually got around it was by calling it when the client first made its connection.

Upvotes: 1

Related Questions