Hi,
I have the following problem: I want to send a type (java.lang.Class) over the wire and 'define' the class on the other side.
I tried like that:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(MyClass.class);
and on the receiving end:
ByteArrayInputStream bis = new ByteArrayInputStream(request.getBytes());
ObjectInputStream ois = new ObjectInputStream(bis);
Class c = (Class) ois.readObject(); // ClassNotFoundException
so obviously I need to send the raw bytecode of the class and do a
ClassLoader.defineClass(bytes, ..
but unfortunately I fail to see how I can retrieve the bytcode of a loaded class. I'm searching for something like:
byte[] byteCode = MyClass.class.toByteArray();
Is this even possible with standard JDK or is there any small lib out there that can do that?
Thank you very much,
Pauli