Creating a new listener class
The Life-cycle Listener wizard enables you to create Java listener classes for various J2EE listener types related to servlet context and session events and attributes.
To create a listener class, do the following:
- Open the Life-cycle Listener wizard. To do this, open the Web perspective and from the Project Explorer, expand the project (that you have created), and expand the deployment descriptor icon. Then right click on the Listener icon, and select New > Life-cycle Listener from the pop-up menu. The Create Listener wizard appears.
- Specify a listener class. To use an existing class, select the appropriate check box and then use the Browse button to locate the class. Otherwise, select Next.
- Supply the following information:
- The folder where the listener class will be placed
- The Java package that the class will belong to (it is added into a default package if you do not specify one)
- The class name of the listener.
Note: You should place the listener in the Java source folder.
- The superclass for the listener class. A listener created by this wizard can have Object, or any class that has Object in its hierarchy, as its superclass. Click Browse to choose from the available superclasses.
- Click Next.
- Select a modifier to specify whether your listener classes are public, abstract, or final. (Classes cannot be both abstract and final.)
- You can also add additional interfaces to implement in addition to the default interfaces. Click Add to open the Interface Selection dialog. In this dialog, as you type the name of the interface that you are interested in adding in the Choose interfaces field, the list of available interfaces listed in the Matching types list box updates dynamically to display only the interfaces that match the pattern. Choose an interface to see the Qualifier and click Add. Click OK when you are finished.
- Choose which method stub you want to create. The Inherited abstract methods and Constructors from superclass options add stubs for inherited abstract methods and superclass constructors that must be implemented (unless you intend to create an abstract listener). One method with the Inherited abstract methods option must be created for the class not to be abstract.
- Click Finish.
The listener class that you created appears under the Listener icon.
Related concepts
The Web deployment descriptor editor