How do I run a method before republishing to JBoss?
Asked Answered
C

1

-1

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.

Carr answered 13/1, 2010 at 15:1 Comment(0)
R
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.

Retort answered 13/1, 2010 at 15:12 Comment(2)
When running the app from Eclipse, you can start/stop the server, run it in debug mode, or just republish, which (as I understand) rebuilds the EAR in the JBoss deploy directory. JBoss sees that the EAR has changed and updates accordingly. Basically, you use "republish" because it's a lot faster than restarting the server (the thing defined in Eclipse, not a physical machine).Carr
Uh OK. And your question is? Edit: or didn't you knew that republish webapp = restart webapp context? When I say "start webapp / shutdown webapp" I didn't mean to say "start appserver / shutdown appserver" as you seem to think.Retort

© 2022 - 2024 — McMap. All rights reserved.