Reputation: 11
I am trying to send a class file to offload "work" from a client to a server. I send a class file "MyClass.class" and receive it as "MyFooClass.class" successfully.
I need to execute the main() of MyFooClass at the server side and return the result.
I am trying to load the MyFooClass with a classloader but get the ClassNotFoundException.
Kindly help.
Aditya
Upvotes: 1
Views: 1027
Reputation: 1941
Yes, you should not rename the class. The classloader will search for MyFooClass.class only but available is MyClass.class..So it is throwing an exception saying the expected MyClass.class is not available.
Upvotes: 1
Reputation: 8679
Unless you are doing RMI, the 'server' side won't have the class in its classpath and therefore fail with a ClassNotFoundException.
Now the bigger questions is why are you trying to send the whole class? I think it would be easier to have the class on the server and then send a text representation (json, xml, yaml, csv) of the state of the class on the client and then have the server read the representation, create the class(es) it needs and execute the work.
Upvotes: 3
Reputation: 8312
The classname and the filename have to match. So you cannot simply rename the file.
Upvotes: 0