I need to send Class
object of a Java class from one JVM on a host to a JVM on another host. What is a good way to do it? I'm trying ByteArrayOutputStream
but it didn't work properly, i.e. the server side couldn't load it in JVM using classloader.
Asked
Active
Viewed 200 times
1

RRM
- 2,495
- 29
- 46
-
2Why do you need to do that? What are you trying to accomplish? – Kayaman Dec 04 '17 at 09:36
-
Have you looked into using serialization? – Tim Biegeleisen Dec 04 '17 at 09:36
-
@TimBiegeleisen of course, I'm using Serialization. `ByteArrayOutputStream` is the class passed to `ObjectOutputStream` in my case. – RRM Dec 04 '17 at 10:18
-
I stopped doing this (shipping classes) and started shipping actual source code in my Java dialect (JavaX). Much easier this way, you never have to go down to bytecode level. – Stefan Reich Dec 04 '17 at 11:55
-
Let your class implements Serializable interface and be sure that serialVersionUID is the same on both systems. Then use writeObject and readObject of ObjectOutputStream and ObjectInputStream. It works. – Sampisa Dec 04 '17 at 14:15
-
Can you add the stack trace that is generated? Can you add the source code that you've implemented? – Claudio Corsi Dec 07 '17 at 23:14
-
Take a look at the following: https://stackoverflow.com/questions/47601251/java-custom-class-loader-issue/47736120#47736120. It is an implementation that you can use to send class files over the wire. – Claudio Corsi Dec 13 '17 at 13:26