At work I have been tasked with some Java serialization issues and I needed a quick way to get the serialversionUid from a class.
I tried the serialver command that comes with the JDK, but I didn't like that I had to setup the full classpath (which for us can be quite large, lots of jars and directories). Instead I wanted it to work in my Eclipse environment which already has this classpath set and is always updated.
I found this site that had a simple way of doing it:
http://www.jguru.com/faq/view.jsp?EID=42982
Thanks Tim!
I wrote up a little wrapper main function:
-
import java.io.ObjectStreamClass;
-
public class SerialVer {
-
if(args.length != 1) {
-
}
-
Class cclass = Class.forName(args[0]);
-
-
long uid =
-
-
sb.append(cclass.getName());
-
sb.append(":\t");
-
sb.append("static final long serialVersionUID = ");
-
sb.append(uid);
-
sb.append("L");
-
}
-
}
Comments
Leave a comment Trackback