Running a batch file before tomcat service starts when user manually starts the service in services.msc

浪尽此生 提交于 2019-12-13 07:08:27

问题


I would like to know if there is any way of running an operation (like, calling a batch file) before a service is started using services.msc?

I want my batch file to run before the service (tomcat installed as service) is actually started, when the user manually clicks 'Start' in Services.

I don't know if this is possible or not. Thank you for your help in advance!


回答1:


The answer to your question is NO, unless you want to modify Apache's procrun (which is written in C language).

Depending on what you wanted to do, you should also check my answer here.

One possible way of doing something when a web application is started - on top my mind - would be to write a javax.Servlet.ServletContextListener as explained here. In you listener's contextInitialized() you would start your BAT file via Runtime.exec() as explained here.



来源:https://stackoverflow.com/questions/9255003/running-a-batch-file-before-tomcat-service-starts-when-user-manually-starts-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!