I have a simple Web App that receives data via a web service and persists it in a database. I am using CXF, Hibernate and Glassfish 3. I am very new to all of this, however I am trying to work out how I can develop a simple plugin model so that when the App fisrt starts up it searches for plugin’s in a folder and calls an instantiation(?) class for each plugin. The issue is that I am not really sure how to initiate this process (that is when the App firsts starts) – how do I know when the app first starts. Any advice/comments appreciated!
ok here is a sample class with the modification of web.xml:
package foo.bar.startup;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class AppStartup implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
// App started - do start up stuff
}
public void contextDestroyed(ServletContextEvent event) {
// App stopped - do something
}
}
<listener>
<listener-class>foo.bar.AppStartup</listener-class>
</listener>
When a web application starts, it fires a
ServletContextEventwhich goes to every registeredServletContextListener. These listeners must be configured in the web.xml of the application: