How do I run a method before republishing to JBoss?

别来无恙 提交于 2019-12-04 06:56:24

问题


I'm developing a J2EE web application and I would like to be able to run a method (or function, class, whatever - something) during the "republish" process. It would be nice if I could control when during the republish my function gets called (before, during, after, etc.) but a good first step would be getting something to be called automatically.

As a temporary hack, I was able to add a button to my web app that you click right before you click "republish" in Eclipse.


回答1:


Implement ServletContextListener to hook on webapp's startup and shutdown.

public class Config implements ServletContextListener {

    public void contextInitialized(ServletContextEvent event) {
        // Do stuff during startup.
    }

    public void contextDestroyed(ServletContextEvent event) {
        // Do stuff during shutdown.
    }

}

To get it to work, just register it in web.xml.

<listener>
    <listener-class>com.example.Config</listener-class>
</listener>

I am however only not sure what exactly you mean with during publish. But you could take a look for another listeners available in the Servlet API or maybe a Filter.



来源:https://stackoverflow.com/questions/2057563/how-do-i-run-a-method-before-republishing-to-jboss

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