在Java中执行通过网络发送的类文件 [英] Executing a class file sent over the network in java

查看:56
本文介绍了在Java中执行通过网络发送的类文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发送一个类文件,以将工作从客户端卸载到服务器。
我发送了一个类文件 MyClass.class,并成功将其接收为 MyFooClass.class。

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.

我需要执行MyFooClass的main()在服务器端返回结果。

I need to execute the main() of MyFooClass at the server side and return the result.

我正在尝试使用类加载器加载MyFooClass,但会收到ClassNotFoundException。

I am trying to load the MyFooClass with a classloader but get the ClassNotFoundException.

请帮忙。

Aditya

推荐答案

除非您在执行RMI时,服务器端的类路径中将没有该类,因此将失败,并出现ClassNotFoundException。

Unless you are doing RMI, the 'server' side won't have the class in its classpath and therefore fail with a ClassNotFoundException.

现在,更大的问题是,为什么要尝试派全班?我认为将类放在服务器上然后在客户端上发送类状态的文本表示形式(json,xml,yaml,csv)会更容易,然后由服务器读取表示形式,创建类( es)它需要并执行工作。

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.

这篇关于在Java中执行通过网络发送的类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆