-1

I have a server project in which I need to send an object via the server from one computer to another. The object is a SpecificGame, which extends Game. The server knows that the object it received is of type Game, but does not have access to SpecificGame or any other class that extends Game. The server would then pass this object on to another computer, and everything was fine.

I have multiple classes that extend Game (several computer games I'm working on use this server) and I am continually modifying and adding these classes, without modifying Game itself.

Recently, however, the server throws a ClassNotFoundException for SpecificGame, even though SpecificGame extends Game which the server recognizes. If I export Server as a jar from the same project folder as SpecificGame in eclipse, it works fine, however this means that I have to export the jar and restart the server every time I modify anything that extends Game and goes through the server.

I have been using the ObjectInputStream.readObject() method to read in the class that extends game, and this has been throwing the exception.

Please help me figure out what might be causing this.

Unfortunately, I cannot post code specifics online.

Thanks!

  • How are you casting the SpecificGame after reading it in? `(Game) ObjectInputStream.readObject()` or `(SpecificGame) ObjectInputStream.readObject()`? – corpico Aug 19 '16 at 02:55
  • I used (Game) so that I could use any class, including SpecificGame, that extends Game with the server – Waiwera Aug 19 '16 at 13:02

1 Answers1

0

When you add a new class to one end of the communication, you of course need to add the same class to the other end as well. And that means, that you will have to redeploy these classes to the server and have to restart it.

Otherwise as in you case the server gets the information to rebuild a SpecificGame object from some serialized information, but how should he do that without knowing what a SpecificGame is?

P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66