在重新发布到JBoss之前,如何运行方法? [英] How do I run a method before republishing to JBoss?

查看:106
本文介绍了在重新发布到JBoss之前,如何运行方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发J2EE Web应用程序,并希望能够在重新发布过程中运行方法(或函数,类,任何 - 某些)。如果我可以在重新发布我的函数被调用(之前,之后,之后等)时控制,但是第一步将是自动调用某些东西。

>

作为一个临时黑客,我可以在点击Eclipse中的重新发布之前点击右键添加一个按钮。

解决方案

实现 ServletContextListener 挂钩webapp的启动和关闭。

  public class Config实现ServletContextListener {

public void contextInitialized(ServletContextEvent event){
//启动时做东西
}

public void contextDestroyed(ServletContextEvent event){
//在关闭期间进行填充。
}

}

要使其正常工作,只需在 web.xml 中注册。

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

然而,我不知道在发布期间你的意思是什么。但是您可以查看Servlet API中可用的其他侦听器,也可以查看过滤器。


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.

解决方案

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.

这篇关于在重新发布到JBoss之前,如何运行方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆