Reputation: 13141
I have a GWT application and I load a .json file on the server side like this:
InputStream source = new FileInputStream(testFile.json);
This works perfectly when I start the application directly in eclipse. However, when I deploy the app on tomcat, it does not work. It seems like, that the application is looking for that file in the bin folder of tomcat (???). However, the correct path would be tomcat/webapps/myProject/testFile.json.
Does anyone know how to get the correct path (without harcoding it)?
Upvotes: 0
Views: 1505
Reputation: 1109745
The FileInputStream
locates files depending on the current working directory, which in turn depends on the way how you started the application, which in turn is thus not controllable from inside your application. In case of web applications, you need ServletContext#getResourceAsStream()
instead of FileInputStream
to obtain web application's own resources. It takes a path which is relative to the web content folder.
InputStream input = getServletContext().getResourceAsStream("/testfile.json");
// ...
Upvotes: 1