Creating Application Life Cycle Listener

Create a Class that extends ApplicationLifecycleListener.

ApplicationListener.java

package demo;

import weblogic.application.ApplicationException;
import weblogic.application.ApplicationLifecycleEvent;
import weblogic.application.ApplicationLifecycleListener;;

public class ApplicationListener extends ApplicationLifecycleListener {

public void preStart(ApplicationLifecycleEvent evt) {
System.out.println(“Event preStart received”);
}

public void postStart(ApplicationLifecycleEvent evt) {
System.out.println(“Event postStart received”);

}

public void preStop(ApplicationLifecycleEvent evt) {
System.out.println(“Event preStop received”);

}

public void postStop(ApplicationLifecycleEvent arg0) throws ApplicationException {
System.out.println(“Event postStop received”);
}
}

Add the listener element in the weblogic-application.xml description present under EAR\META-INF

weblogic-application.xml

<weblogic-application
xmlns=”http://www.bea.com/ns/weblogic/90″
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
<listener>
<listener-class>demo.ApplicationListener</listener-class>
</listener>
</weblogic-application>

1. Compile the ApplicationListener class and place it under EAR\APP-INF\classes

2. Create a simple Web Application and specify the web module in the application.xml present under EAR\META-INF

application.xml

<module>
<web>
<web-uri>TestApp</web-uri>
<context-root>TestApp</context-root>
</web>
</module>

5. Deploy the EAR.

7 comments

  1. In which jar file I can find this class weblogic.application.ApplicationLifecycleListener?
    I need to jar file.

    Thanks
    Uma

Leave a Reply