Listeners are unique to JIRA, and a very powerful way to extend it.
JIRA has a complete event subsystem which fires events whenever anything happens inside the application. For
example an ISSUE_CREATED event is fired whenever an issue is created.
A Listener is a class that implements one of the Listener interfaces. It is then called whenever events occur in
JIRA. Using those events, you can then perform any action you want. For example the email sent by JIRA is driven
by the MailListener.
Listeners are most useful when you want to drive or affect external systems from events which occur within
JIRA.
Listener Interfaces
There are currently two different concrete Listeners within JIRA (both of which extend the base JiraListener
interface).
| com.atlassian.jira.event.JiraListener |
The base interface which all other JIRA listener interfaces extend. Covers core listener properties like
uniqueness, description, parameters etc.
API doc
|
|
com.atlassian.jira.event.issue.IssueEventListener
|
The main listener interface in JIRA, used whenever anything happens to an issue.
API doc
|
| com.atlassian.jira.event.user.UserEventListener |
This listener is called whenever anything happens to a user within JIRA.
API doc
|
Example Listeners
The examples provided may be freely used and modified for use in your own environment. The source of all
examples is available and should give you good overview of how simple it is to write your own listeners. Both
example listeners are included with JIRA 2.1, and both implement UserEventListener and
IssueEventListener.
-
DebugListener (source)
-
This is a very simple listener that prints events and their content to System.out whenever they are
received.
To test this listener, add a listener with the class
com.atlassian.jira.event.listeners.DebugListener.
-
MailListener (source)
-
This listener is how mail notifications are currently sent from within JIRA, and a good example of a more
complex listener. It basically listens for events, and turns them into email notifications using Velocity
templates to generate the mail bodies.
This listener is usually always turned on in JIRA - see Email Notifications for
more details. If you want to write more complex or more specific notifications, you can disable the internal
MailListener and add your own.
Other examples of useful tasks that can be accomplished with listeners are:
- Send SMS or IM notifications
- A listener could easily send
notifications for various events via SMS or instant messenger (eg ICQ or AIM)
- or anywhere that you have a Java library to send messages.
- Group notifications:
- A listener could notify certain groups
of issue changes, depending on the content of the issue. For example any issue
containing "windows" in the environment could notify your "windows-developers"
group.
Registering a Listener
To register a listener:
- Make sure your listener class is in the classpath where JIRA can see it
- the best locations are usually the WEB-INF/classes or WEB-INF/lib
(as a JAR) directories within the JIRA web application.
- Log in as a user with the 'JIRA System Administrators' global permission.
-
Bring up the administration page by clicking either the 'Administration' link on the top bar or the title of the
Administration box on the dashboard:


- Click the Listeners link in the System section of the left-hand navigation column.
- Enter a Name (a nice name for this listener) and Class
(the fully qualified class of your listener) for your listener and click
Add.
- The listener will now be added. Click Edit for your listener
to edit its properties.
Editing Listener Properties
At any time you can edit a listeners properties by clicking Edit for that listener in the
Listeners section of the Administration tab.
Removing a Listener
To remove a listener, just click Del for that listener in the Listeners
section of the Administration tab.
Custom Events
With the ability to add custom events to JIRA, the Listener must be updated to deal
with the event as appropriate. This is possible by providing an implementation for the method customEvent(IssueEvent event)
in the Listener. For example, the MailListener implementation passes the custom event on for notification
processing. The DebugListener logs that the custom event has been fired.