Re: How to find war file name programmatically?
ServletContext.getRealPath("/") works for me.Thanks. On Tuesday, August 13, 2019, 01:43:35 AM PDT, Mark Thomas wrote: On 12/08/2019 23:18, W wrote: > Hi, > I would like to find the war file name (for example, > ROOT##2019-08-12-10-44.war) inside > ServletContextListener.contextInitialized() and > ServletContextListener.contextDestroyed(). So I can send email to admins warn > them which app is up and down. > Is there a way to do it? It isn't guaranteed to work in all circumstances but try: ServletContext.getRealPath("/") If that doesn't work then - assuming you can use reflection - something along these lines: Obtain the ServletConext. Cast it to org.apache.catalina.core.ApplicationContext Use reflection to read the context field or call getContext() which will return a StandardContext instance. Then you have various options: - call getDocbase() - call getPath() and getWebappVersion() and there are probably plenty of other similar approaches that would work. Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: How to find war file name programmatically?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Mark, On 8/13/19 04:43, Mark Thomas wrote: > On 12/08/2019 23:18, W wrote: >> Hi, I would like to find the war file name (for example, >> ROOT##2019-08-12-10-44.war) inside >> ServletContextListener.contextInitialized() and >> ServletContextListener.contextDestroyed(). So I can send email to >> admins warn them which app is up and down. Is there a way to do >> it? > > It isn't guaranteed to work in all circumstances but try: > > ServletContext.getRealPath("/") > > If that doesn't work then - assuming you can use reflection - > something along these lines: > > Obtain the ServletConext. Cast it to > org.apache.catalina.core.ApplicationContext > > Use reflection to read the context field or call getContext() which > will return a StandardContext instance. > > Then you have various options: - call getDocbase() - call getPath() > and getWebappVersion() > > and there are probably plenty of other similar approaches that > would work. It seems like this might be an opportunity to add some information to the context as a convenience for the application. I'm not sure it's really relevant to the application what it's "host file/directory" is, but it would be easy to add something like a context attribute "org.apache.tomcat.context.source" which is of type java.io.File and is either a directory or a WAR file. - -chris -BEGIN PGP SIGNATURE- Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/ iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl1S+aoACgkQHPApP6U8 pFgRkQ/+OTHo6Hdv+wZATo4ahnupSLIjYo58UJOFkdi1qu84x6S1ZqXxG4An6cfB /lRskrn+7zn/dVgh4VJvYfZTZ2m+sGv8XqI+X7LRQPiwOXh2HXjxNLXjU3PeY08C S6M6Nvc40MOHEYHylTVuKizRsNSEED50ekrDUwXx5TVH3ygV+Kn2doDN6y8uhc8P VQEd4Z1e+yVPMFuJLY/utHsC8ey7tE7aioBLasAD14jyRMWtE3ePpnbf76cyhaLj vD41XrPjYobdfmxAYyPdHiMSE+KPqL96ZjmPTom880Hjm8qIs4amTjrM7z831mNx tCsv/5rI1C2b+Ol8gq69y0tP4rEkAwBAul5CV6ilNSJoDwGDjyt+e0lNsxBRBLJ3 POXWtGAGD3uov0BHrXcpqyYhxse5z6iTVLokNuFW6O3AS9NyhnWogYG9XzfGGLm6 +G6YaFGFSnvIkVCujYMYYHAfGEotHzYbRN/gPgh3sJdAwglDej9Cb8jVr1okeulg F64R6TJCzUCAUhz4L7p6UDvKRzc+opRxd4QYrB7TlqnYFkK9UK90wA+BhOt404JQ iq0wj2pl/cvRFOolxlJE488NonXYMvoNBZNQiwam144ONPKQ8+i82RFZeC3VSpUj oAfDrYPc25sezg68NjA+XPPiQyI0yjwk+GChvzDYTCn//gUy33k= =DMlI -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: How to find war file name programmatically?
On 12/08/2019 23:18, W wrote: > Hi, > I would like to find the war file name (for example, > ROOT##2019-08-12-10-44.war) inside > ServletContextListener.contextInitialized() and > ServletContextListener.contextDestroyed(). So I can send email to admins warn > them which app is up and down. > Is there a way to do it? It isn't guaranteed to work in all circumstances but try: ServletContext.getRealPath("/") If that doesn't work then - assuming you can use reflection - something along these lines: Obtain the ServletConext. Cast it to org.apache.catalina.core.ApplicationContext Use reflection to read the context field or call getContext() which will return a StandardContext instance. Then you have various options: - call getDocbase() - call getPath() and getWebappVersion() and there are probably plenty of other similar approaches that would work. Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org