I am writing a web application in Java using Tomcat as servlet container. I wrote a AppLoader class implementing ServletContextListener to trap the event contextInitialized and perform some init operations. No problem about that, but when I need to read the content of a resource (txt file) using the getResourceAsStream method, it fails and returns null. I noticed that the same operation run in a Servlet service (so, after the web app init event) works fine and returns the file content.
It seems I can't access internal resources until the app is loaded.
How can I solve? Is there a "ready" event to trap for a web app?
Thank you for any suggestion
you can also do it by loading a servlet with load on Statup automatically , and call getResourceAsStream() method in init of servlet like this
In Servlet