1

I have 2 project:

1) Client - Android
2) Server - Google App Engine

At server-side I have class Entity that is called as Profile.
I included it in buildpath of the client the server project. I'm creating a new instance of the profile in the client sending it to the server and storing it in JPA DB.
at the server side after specific time I send from the server vector with all the clients in the server to the user.

The problems is:

when I'm adding the build path of the Profile I get:

The project was not built since its build path is incomplete. Cannot find the class file for javax.jdo.spi.PersistenceCapable. 
The type javax.jdo.spi.PersistenceCapable cannot be resolved. It is indirectly referenced from required .class files

So in the client I'm adding the jdo2-api-2.3-eb.jar. and the problem seems disappear. But at runtime when I'm sending the Profile Vector form the server to the client I get:

 java.io.InvalidClassException: javax.jdo.identity.LongIdentity; Incompatible class (SUID): javax.jdo.identity.LongIdentity: static final long serialVersionUID =2472141538875317527L; but expected javax.jdo.identity.LongIdentity: static final long serialVersionUID =2940818939440220368L; 

that I believe is caused by jdo2-api-2.3-eb.jar that i added.

So I'm asking how to do this correctly? I understand that Maven or Ant can solve this problem but it seems very messy. Is there any old way by just using basic Eclipse to solve this? If Not I'll appreciate other solution that comes with good tutorial.

Rahul Borkar
  • 2,742
  • 3
  • 24
  • 38
Rami
  • 2,098
  • 5
  • 25
  • 37

3 Answers3

1

I would use a non-binary format for transporting the data, such as JSON or XML. Trying to use binary serialization is going to lead to headaches, even once you get your build path problem sorted out and even if you use a more simple "transport" bean objects. For example, when you want to udpate either the client or the server, you have to keep them perfectly in sync (the JARs), you can't have an old client communicate with a new server (or vice versa) without a LOT of extra work. But by using JSON or XML, the client and server can evolve somewhat independently.

Working with either XML or JSON on Android is very straightforward, same for Java EE (server).

E-Riz
  • 31,431
  • 9
  • 97
  • 134
0

In my case we have a lot of hibernate objects. You can't send these objects to a client for various reasons. You are in the same boat.

In my projects I create separate simple beans used to transport the data between the server and client. There is then also code for translating from the internal objects to these outside portable, serializable objects and back. We used to use RMI to send these objects back and forth. These days we use Hessian.

You would put these classes in a separate project so that you can have both the client and the server have them in their classpath.

Sarel Botha
  • 12,419
  • 7
  • 54
  • 59
0

You need to put the Entity classes in a jar and distribute the same version of the jar to the server and to the client. While deserializing the objects the JVM will check if they belongs to the same version of the class using the serialVersionUID

Better if in any Entity you declare the serialVersionUID

Community
  • 1
  • 1
Teg
  • 1,302
  • 13
  • 32
  • If this is a new app you don't actually have to generate the serialVersionUID. Just set it to 1L. If you have deployed this to clients already and need to remain compatible with them then you need to run serialver to get this number and set it to this number. – Sarel Botha Apr 23 '12 at 13:19
  • Thanks for your comment, I replaced "generate" with "declare" – Teg Apr 23 '12 at 13:29
  • I still get: The project was not built since its build path is incomplete. Cannot find the class file for javax.jdo.spi.PersistenceCapable. The type javax.jdo.spi.PersistenceCapable cannot be resolved. It is indirectly referenced from required .class files – Rami Apr 23 '12 at 13:56
  • You must provide the jdo2-api-2.3-eb.jar as you already done, and deliver this jar with the Entity jar in the server and in the client – Teg Apr 23 '12 at 14:05