从签名的小程序加载 Java 类
如果我正在运行一个签名的 Java 小程序。 我可以从远程源、同一域甚至同一主机加载其他类并运行它们吗?
我想在不更改页面甚至停止当前小程序的情况下执行此操作。 当然,所有类的总大小太大,无法一次加载它们。
有没有办法做到这一点? 有没有办法用签名的小程序来做到这一点并保持它们的“信任”状态?
If I'm running a signed Java applet. Can I load additional classes from remote sources, in the same domain or maybe even the same host, and run them?
I'd like to do this without changing pages or even stopping the current applet. Of course, the total size of all classes is too large to load them all at once.
Is there a way to do this? And is there a way to do this with signed applets and preserve their "confidence" status?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为小程序中的类是延迟加载的。 按需加载。
无论如何,如果类位于 jar 之外,您可以简单地使用 applet 类加载器并按名称加载它们。 例如:
如果您想从 jar 加载类,我认为您需要使用 jar 的 url 创建 URLClassLoader 的新实例。
默认情况下,小程序被禁止创建新的类加载器。 但是,如果您签署您的小程序并包含创建新类加载器的权限,您就可以做到这一点。
I think classes are lazy loaded in applets. being loaded on demand.
Anyway, if the classes are outside of a jar you can simply use the applet classloader and load them by name. Ex:
If you want to load classes from a jar I think you will need to create a new instance of URLClassLoader with the url(s) of the jar(s).
By default, applets are forbidden to create new classloaders. But if you sign your applet and include permission to create new classloaders you can do it.
听起来应该是可能的(但我从未这样做过)。 您是否已经看过远程方法调用 (RMI)?
Sounds like it should be possible (but I've never done it). Have you already had a look at Remote Method Invocation (RMI)?
是的,您可以打开与运行小程序的主机的 URL 连接。 您可以使用 HTTP url 创建类加载器,也可以将类(作为 jar)下载到用户的计算机上,并在类路径中使用这些 jar 创建类加载器。 小程序不会停止,您不需要加载另一个页面。
关于您关于信心的问题的第二部分,一旦用户授予对您的小程序的访问权限,它就可以下载任何内容,是的,任何内容,它都可以下载到本地计算机。 如果您的 UI 设计允许,您可以告知用户它正在做什么。
希望这可以帮助。
Yes, you can open URL connections to the host you ran your applet from. You can either create a classloader with HTTP urls, or download the classes (as jars) to the user's machine and create a classloader with those jars in the classpath. The applet won't stop and you don't need to load another page.
Regarding the second part of your question about confidence, once the user has granted access to your applet it can download anything, yes anything, it wants to the local machine. You can probably inform the user as to what it's doing, if your UI design permits this.
Hope this helps.