The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi,
I'm trying to run the example of a Crowd plugin with Event Listeners but it does not work.
I see differences between the official documentation and the repository example. For example, in the repository there is no listener section in atlassian-plugin.xml.
I have replaced the "System.out.println" line with a slf4j logger, but it also does not print any logs when a user is created.
If I add the listener section in atlassian-plugin.xml, when I launch Crowd it returns an error of ClassNotFoundException:
2022-06-16 09:48:53,336 localhost-startStop-1 ERROR [atlassian.plugin.manager.DefaultPluginManager] There was an error loading the descriptor 'User Created Listener' of plugin 'com.atlassian.crowd.example.crowd-event-listener-example'. Disabling.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.atlassian.crowd.event.listener.example.UserCreatedListener': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.atlassian.crowd.event.listener.example.UserCreatedListener] from ClassLoader [com.atlassian.crowd.example.crowd-event-listener-example [28]]
at com.atlassian.crowd.console.listener.StartupListener.contextInitialized(StartupListener.java:101)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4705)
Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.atlassian.crowd.event.listener.example.UserCreatedListener] from ClassLoader [com.atlassian.crowd.example.crowd-event-listener-example [28]]
Caused by: java.lang.ClassNotFoundException: com.atlassian.crowd.event.user.UserCreatedEvent not found by com.atlassian.crowd.example.crowd-event-listener-example [28]
This is the source code (without the listener section):
UserCreatedListener.java
package com.atlassian.crowd.event.listener.example;
import com.atlassian.crowd.event.user.UserCreatedEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class UserCreatedListener{
private static final Logger log = LoggerFactory.getLogger(UserCreatedListener.class);
@com.atlassian.event.api.EventListener
public void printUserCreatedEvent(UserCreatedEvent event) {
log.debug("User " + event.getUser().getDisplayName() + " has been created.");
}
}
atlassian-plugin.xml
<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
<plugin-info>
<description>${project.description}</description>
<version>${project.version}</version>
<vendor name="${project.organization.name}" url="${project.organization.url}" />
</plugin-info>
</atlassian-plugin>
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.atlassian.crowd.event.listener.example</groupId>
<artifactId>crowd-event-listener-example</artifactId>
<version>1.0.1-SNAPSHOT</version>
<organization>
<name>Example Company</name>
<url>http://www.example.com/</url>
</organization>
<name>event-listener-example</name>
<description>This is an event listener plugin for Atlassian Crowd.</description>
<packaging>atlassian-plugin</packaging>
<repositories>
<repository>
<id>atlassian-public</id>
<url>https://packages.atlassian.com/mvn/maven-external/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>atlassian-public</id>
<url>https://packages.atlassian.com/mvn/maven-external/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<checksumPolicy>warn</checksumPolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>com.atlassian.crowd</groupId>
<artifactId>crowd-events</artifactId>
<version>${crowd.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.event</groupId>
<artifactId>atlassian-event</artifactId>
<version>4.1.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>crowd-maven-plugin</artifactId>
<version>8.2.3</version>
<extensions>true</extensions>
<configuration>
<productVersion>${crowd.version}</productVersion>
<productDataVersion>${crowd.data.version}</productDataVersion>
<enableQuickReload>true</enableQuickReload>
<instructions>
<Import-Package>
com.atlassian.event.*
</Import-Package>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<crowd.version>4.3.5</crowd.version>
<crowd.data.version>4.1.10</crowd.data.version>
</properties>
</project>
Thanks!
Hey @CARLOS MEDINA SANCHEZ and welcome to the community!
I tried to download and run this example and have same problem as you have: ClassNotFoundException, when I was running my Crowd.
I can describe my way to solve this issue:
1) I created my custom crowd plugin with command:
atlas-create-crowd-plugin
2) Then I updated my atlas-create-crowd-plugin-module. That will allow you to use Crowd 4.4.
AMPS_PLUGIN_VERSION="8.5.0"
3) I added UserCreatedListener class and dependencies to newly created project.
Also you can use different log levels. Other way to enable DEBUG level use this how to. Just for fun I enabled them all:
System.out.println("User " + event.getUser().getDisplayName() + " has been created.");
log.info("User " + event.getUser().getDisplayName() + " has been created.");
log.warn("User " + event.getUser().getDisplayName() + " has been created.");
log.debug("User " + event.getUser().getDisplayName() + " has been created.");
log.error("User " + event.getUser().getDisplayName() + " has been created.");
4) Then I used this command to run Crowd 4.4 with my plugin.
mvn crowd:run
And after I created user I had this message in logs:
I hope this small guide will help you to resolve the issue.
upd:
You can find atlas-create-crowd-plugin-module file in your atlassian-plugin-sdk folder. For me it was:
/usr/local/Cellar/atlassian-plugin-sdk/8.2.7/libexec/bin/atlas-create-crowd-plugin-module
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello everyone, Hope everyone is safe! A few months ago we posted an article sharing all the new articles and documentation that we, the AMER Jira Service Management team created. As mentioned ...
Connect with like-minded Atlassian users at free events near you!
Find an eventConnect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.
Host an eventYou're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.