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)?
The
FileInputStreamlocates 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 needServletContext#getResourceAsStream()instead ofFileInputStreamto obtain web application’s own resources. It takes a path which is relative to the web content folder.See also: