Search code examples
osgiclassnotfoundexceptionhazelcast

Hazelcast & OSGI: ClassNotFoundException


I have a OSGI (Equinox-based) platform running a bundle. This bundle connects to Hazelcast for retrieving some data with:

ClientConfig clientConfig = new XmlClientConfigBuilder(configIs).build();
clientConfig.setClassLoader(com.MyClass.class.getClassLoader());
HazelcastInstance instance = com.hazelcast.client.HazelcastClient.newHazelcastClient(clientConfig);

But at runtime (instance.getMap(map).values()), during the deserialization of com.MyClass, I got the followin exception:

com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: com.MyClass

I don't really understand why Hazelcast would not be able to find com.MyClass, especially with the way I am calling the setClassLoader() method. The com.MyClass btw implements Serializable interface.

I know integrating Hazelcast with OSGI seems to be a common difficulty but I've not been able to find a resolution so far..

Any help would be appreciated :)

Edit:

  • Hazelcast version: 3.7.1
  • When I use the OBJECT in memory map format, I got the error during serialization & deserialization. With BINARY in memory map format, I got the error only during deserialization
  • Apparently this is not related to OSGI. I am facing the very same issue with a "normal" Java app. I just face the issue when I am using the values() method using a Predicate.

Solution

  • I solved my issue. If one day someone faces the very same one, please not that Predicate are managed on server side. It means you must import the bean class in the Hazelcast classpath.