Today I have a problem reading the server.xml config file from Tomcat. What I mean by that is I want to verify the app context on server start so the app will know which configuration file to look for.
For example: I have in my Tomcat server configuration set a context for my app "/myapp". So it will be accessible by the :8080/myapp.
No I want my Java application to read the server.xml file on Tomcat startup, so it will look more-or-less like this: - Tomcat is starting, - App is checking the server.xml file for itself context parameter, and finds that it's "/myapp", - Using the above context - the app looks for file /CATALINA_BASE/conf/myapp.conf.
I can't base on the URI because the app starting with Tomcat and doesn't require to open the web browser, so no URI is provided on startup.
Thank you in advance! Tom
You shouldn't parse server.xml, as it's not guaranteed that your app is declared there (in fact, it's bad style to do so). The application's context path can be determined within a ServletContextListener
from ServletContext.getContextPath()
.