所以我有两个项目。其中一个是servlet
,另一个是JFrame
。我试图在servlet
中读取序列化的对象,但我得到了ClassNotFoundException
。只有当我把所有类都放在我的servlet
项目中编译它们时,它才开始工作。这是它应该的工作方式吗?serialization
是否取决于编译的项目?(当然,如果类相同)
例如,我的班级的UPD定义图在servlet
和JFrame
类中。
来自 javadocs
When an object is serialized, information that identifies its class is recorded in
the serialized stream. However, the class's definition ("class file") itself is
not recorded. It is the responsibility of the system that is deserializing the
object to determine how to locate and load the necessary class files.
反
序列化将需要.class文件从序列化流创建对象。由于序列化对象不包含类定义,因此如果没有.class文件,则无法从流中提取对象。