|
|
Serialize a class (not an object)
I want to send a class (compiled java file, not an object) over RMI so
that the receiving party can instantiate objects with that class file.
Using an RMI codebase is sub-optimal since the type of class is
dynamically generated and will thus change very often. Is there a way
to serialize the class file, send it to the receiver, have him add it
to his classpath and use it to instantiate objects?
|
|
0
|
|
|
|
Reply
|
cyberco (119)
|
5/4/2006 3:12:07 PM |
|
"cyberco" <cyberco@gmail.com> wrote in message
news:1146755527.215980.185280@j73g2000cwa.googlegroups.com...
>I want to send a class (compiled java file, not an object) over RMI so
> that the receiving party can instantiate objects with that class file.
> Using an RMI codebase is sub-optimal since the type of class is
> dynamically generated and will thus change very often. Is there a way
> to serialize the class file, send it to the receiver, have him add it
> to his classpath and use it to instantiate objects?
Serialization is taking conceptual data, and turning it into a sequence
of bytes. Assuming you actually HAVE the class *FILE* somewhere, the file
itself is nothing more than a sequence of bytes. So just send the file.
- Oliver
|
|
0
|
|
|
|
Reply
|
owong (5281)
|
5/4/2006 3:49:08 PM
|
|
On Thu, 2006-05-04 at 15:49 +0000, Oliver Wong wrote:
> So just send the file.
So on the receiving end, what kind of hoops do you have to jump through
to get a classloader to load such a file? Just curious.
James
|
|
0
|
|
|
|
Reply
|
jmcgill1 (236)
|
5/4/2006 4:34:27 PM
|
|
"James McGill" <jmcgill@cs.arizona.edu> wrote in message
news:1146760460.15379.8.camel@localhost.localdomain...
> On Thu, 2006-05-04 at 15:49 +0000, Oliver Wong wrote:
>> So just send the file.
>
> So on the receiving end, what kind of hoops do you have to jump through
> to get a classloader to load such a file? Just curious.
From http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ClassLoader.html:
<quote>
A class loader is an object that is responsible for loading classes. The
class ClassLoader is an abstract class. Given the binary name of a class, a
class loader should attempt to locate or generate data that constitutes a
definition for the class. A typical strategy is to transform the name into a
file name and then read a "class file" of that name from a file system.
[...]
Normally, the Java virtual machine loads classes from the local file system
in a platform-dependent manner. For example, on UNIX systems, the virtual
machine loads classes from the directory defined by the CLASSPATH
environment variable.
However, some classes may not originate from a file; they may originate from
other sources, such as the network, or they could be constructed by an
application. The method defineClass converts an array of bytes into an
instance of class Class. Instances of this newly defined class can be
created using Class.newInstance.
</quote>
- Oliver
|
|
0
|
|
|
|
Reply
|
owong (5281)
|
5/4/2006 5:08:24 PM
|
|
"cyberco" <cyberco@gmail.com> wrote in message
news:1146755527.215980.185280@j73g2000cwa.googlegroups.com...
>I want to send a class (compiled java file, not an object) over RMI so
> that the receiving party can instantiate objects with that class file.
> Using an RMI codebase is sub-optimal since the type of class is
> dynamically generated and will thus change very often. Is there a way
> to serialize the class file, send it to the receiver, have him add it
> to his classpath and use it to instantiate objects?
>
RMI already does that transparently. You just have to ensure that your
SecurityManager permits the loading of the class over the wire.
--
Tony Morris
http://tmorris.net/
|
|
0
|
|
|
|
Reply
|
not147 (444)
|
5/4/2006 11:12:26 PM
|
|
I want to do the same as cyberco. I generate some source code
(dynamicly) and i want to compile it when a client asks for the code.
At the moment i'm looking at www.janino.net's inline compiler. Is it
good or is there a better one? I'd rather not use the filesystem to
store the source and then run javac.
With Janino i can compile and instantiate classes so the compiling part
is working.
Tony Morris schreef:
>
> RMI already does that transparently. You just have to ensure that your
> SecurityManager permits the loading of the class over the wire.
Tony. Could you describe how i can send this (in memory) class to the
client so it can instantiate and run it? Do you have some useful URL's?
tnx
GJ
|
|
0
|
|
|
|
Reply
|
gjlubbertsen
|
5/5/2006 4:32:24 PM
|
|
|
5 Replies
40 Views
(page loaded in 0.178 seconds)
|
|
|
|
|
|
|
|
|