In a general servlet class after deployment, you can access the application root as servletContext.getRealPath("/") to access any of the properties files in the "WEB-INF" directory or anywhere else in the /webapp-root/ directory.
How can we get the equivalent servletContext.getRealPath("/") in a non-servlet where you are interested to access a property file located in "/webapp-root/WEB-INF" or probably a text file stored in a static folder pages in the /webapp-root/pages/ folder.
1.) dynamic read
get the windows environment variable for the webserver directory (e.g tomcat) and add ""/webapp-root/WEB-INF" to it. (or parse the tomcat configuration file where you have mapped the web-directory to a real path on your harddisk )
2.) hardcode read
- or you can just make a configuration file, which will be read from your non-servlet program, and put the whole path there inside,
- or you can pass the folder as a parameter to java when you start your non-servlet program
- or you can set thepath inside a (windows) environment variable and read it from there.
3.) database read
store the path inside a database table when you run the servlet. Then read this path when you run your non-servlet app.
4.) remote read:
use RMI, Corba or other ways (Sockets, pipes, shared memory) to pass the
path from one program to another.