I saved a PublicKey instanc开发者_如何学Ce in a file using ObjectOutputStream. This file is then stored inside a jar file which is then loaded by JBoss. I'm trying to read this file but it throws me an exception telling that it's not serializable. Here is the code :
InputStream input = KeyLoader.class.getClassLoader().getResourceAsStream(resource); ObjectInputStream objectInputStream = new ObjectInputStream(input); Object obj = objectInputStream.readObject(); Key output = (Key) obj; objectInputStream.close(); return output;
which throws me this exception An exception occurred: java.io.NotSerializableException
I'm not sure about serialization/deserialization from within a jar file, but without being able to see the rest of your code, I can say a few things:
- make sure that all of the classes that you are trying to serialize/deserialize implement Serializable.
- If you can't do number 1, then you might try getting an encoded form of the Key object, such as
key.getEcnoded()
, which would allow you to do input/output using the bytes of the key.
Edit: I'm not really familiar with JBoss, but maybe try using JBossObjectInputStream and JBossObjectOutputStream (org.jboss.serial.io). You will also have to add jboss-serialization.jar to your classpath. see link
also, I've never done this sort of thing before, but if you think the jar file is complicating things, but you should be able to use some of the classes in the java.util.jar
package to simplify IO operations with jar files.
I hope this helps in some way.
精彩评论