0

I wrote a Java class, let A, which must be compiled once and saved in several directories (let Y, and Z). Therefore, the compiled files would have the same SerialVersionUID (I need it), in any directory (Y and Z).

I tried to make use of javac A.java -d Y -d Z but it doesn't work.

By the way, I can't make a first compilation and then a copy (i.e. : javac A.java -d Y; cp Y/A.class Z), because the SerialVersionUID will be different...

How could I solve this problem ?

EDIT : an ultimate solution would be to set the SerialVersionUID definitively in the .java files, but I would want to avoid it.

JarsOfJam-Scheduler
  • 2,809
  • 3
  • 31
  • 70
  • Specify the serial version uid explicitly. Then copy from the first to second directory. Why do you want to avoid this? – Andy Turner Mar 05 '17 at 17:54
  • In the `javac` command ? Or in the .java files ? – JarsOfJam-Scheduler Mar 05 '17 at 17:56
  • No, in the source code. – Andy Turner Mar 05 '17 at 17:56
  • Well if it's the only one solution ok =/ I find it quite dirty in fact – JarsOfJam-Scheduler Mar 05 '17 at 17:57
  • 4
    The serialVersionUid of a class doesn't depend on where the .class file is stored on your disk. Your question doesn't make much sense, because it's based on incorrect assumptions. It's also unclear 1. why you deal with .class files and not jar files, 2. why you need a .class file in two separate directories. – JB Nizet Mar 05 '17 at 17:58
  • 3
    Note: if you need to care about the value of serial version uid, you should specify it explicitly anyway. Otherwise you could compile the same class on two compilers and get different values. – Andy Turner Mar 05 '17 at 17:58
  • 2
    "However, it is strongly recommendedthat all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected InvalidClassExceptions during deserialization. Therefore, to guarantee a consistent serialVersionUID value across different java compiler implementations, a serializable class must declare an explicit serialVersionUID value." From java.io.Serializable. – Andy Turner Mar 05 '17 at 18:01
  • 1
    Copying a class file does not change its `serialVersionUID`, nor does recompiling it (assuming the source is the same). – john16384 Mar 05 '17 at 18:45
  • Well thank you guys, I wrote a precise sVUID, but the problem seems to be elsewhere (I created a new question https://stackoverflow.com/questions/42612408/despite-recompilation-still-the-error-local-class-incompatible-stream-classd ) – JarsOfJam-Scheduler Mar 05 '17 at 18:47

0 Answers0