Custom CacheListener class not found after gfsh deploy in VMware GemFire
search cancel

Custom CacheListener class not found after gfsh deploy in VMware GemFire

book

Article ID: 443165

calendar_today

Updated On:

Products

Pivotal GemFire VMware Tanzu Gemfire

Issue/Introduction

When deploying a custom CacheListener (such as a ServerDestroyListener) to a GemFire cluster using "gfsh deploy", the listener may fail to trigger, and the server logs may not show any activity from the listener. This often occurs when the listener class is missing from the deployed JAR file, even if the build appears successful.

Symptoms

  • "gfsh alter region" fails with "ClassNotFoundException" or "Error instantiating class"
  • Custom logs within "afterDestroy" or "initialize" methods do not appear in GemFire server logs
  • The listener is not visible in "gfsh describe region --name=RegionName" Non-Default Attributes section
  • Errors such as "UnsupportedClassVersionError" may appear if there is a Java version mismatch between the build

Environment

  • VMware Tanzu GemFire

Cause

The issue is typically caused by a Maven project structure that does not follow the standard "src/main/java" layout. If the listener source code resides in a sub-folder (e.g. server-listener/src/main/java), the default Maven compiler plugin will not include the classes in the final JAR unless the sourceDirectory is explicitly defined in the pom.xml file.

Resolution

Follow these steps to ensure the listener class is correctly bundled and deployed.

1. Verify JAR Contents:

    Run the following command to check if the listener class exists in the JAR:

jar -tf your-listener-file.jar | grep ListenerName

    If no output returns, the class was not bundled.

2. Update pom.xml:

    If using a non-standard directory structure, add the "sourceDirectory" and "resources" tags to the <build> section of the pom.xml:

<build>
	<sourceDirectory>server-listener/src/main/java</sourceDirectory>
		<resources>
			<resource>
				<directory>server-listener/src/main/resources</directory>
		</resource>
	</resources>
</build>

3. Check Java Version Compatibility:

    Ensure the JAR is compiled with a Java version supported by the GemFire server (see Java Support doc for your Gemfire version).

4. Redeploy and Register:

  • Undeploy the old JAR:
    gfsh undeploy --jar=your-listener-file.jar
  • Deploy the new JAR:
    gfsh deploy --jar=target/your-listener-file.jar
  • Attach to region:
    gfsh alter region --name=/your_region --cache-listener=com.package.ListenerClass

Additional Information