Simon Simon - 1 year ago 56
Scala Question

Akka remote: is it possible to work with classes from two differents app which don't have the same package name?

I have two applications communicating by Akka remote.

I have one class in my first application in a pachage


case class A()

and the same one in my second application but in a different package

case class A()

But when I get by an actor message with an instance of the class
I get a
java.lang.ClassNotFoundException: a.A
because of the different package names.

Is there a way to easily avoid this?

Answer Source

What you want would require a full classpath scan (what if there is a third mypackage3.A which has also the same SerialVersionUID? How does the JVM know that it has to deserialize mypackage1.A into another type?) and obviously SerialVersionUID is not meant for this. It is only meant to track serialization-compatibility across multiple version of the same class.

Have a read What is a serialVersionUID and why should I use it?

So you have two options:

  • You use manually deserialize the byte array from mypackage1.A into mypackage2.A
  • You share the data model and you avoid having two identical classes in two different packages in two different apps
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download