Java 小程序从外部 jar 加载图像

发布于 2024-08-27 09:31:07 字数 880 浏览 4 评论 0原文

我在服务器上有一个 jar,用户应该能够为其开发扩展。因此,应该扩展 jars 主类,并且应该将一些资源添加到第二个用户创建的 jar 中,该 jar 将从另一个服务器或本地加载。现在我在从用户加载的 jar 访问资源(图像)时遇到问题。结构如下:

My Server:
  game.jar containing
    game.class
    images.class
    ...
    image1.png (...)

Local:
  user.jar containing:
    user.class extends game
    userimage.png

扩展通过 Greasemonkey 加载,它将“archive”属性修改为“/home/username/user.jar, game.jar”,将“code”属性修改为“user.class”。用户应该能够覆盖已经定义的图像。如果 game.jar 中不存在该图像,则会从 user.jar 中正确加载该图像。但是游戏早期加载的图像总是从 game.jar 加载,其他图像似乎被用户正确覆盖。有没有办法确保它们始终以正确的顺序加载?这可能是由于某些缓存机制造成的。由于 Greasemonkey 从页面中删除了游戏,更改了存档和代码并重新插入,因此游戏会在没有 mod 的情况下加载短暂的一秒钟。此时,图像会按预期从游戏 jar 中加载,但这些图像不能被用户覆盖。但如何避免呢?

另一件事: 如果我覆盖 user.class 中的“run”方法,游戏将根本无法加载任何图像。不是来自 user.jar 也不是来自 game.jar。 Java 找不到图像,因为 URL 对象“getClass().getResource(imagename)”返回 null。我尝试覆盖 image.class,但这并不能解决问题,除非我覆盖 game.class 中涉及调用 image.class 的每个类

I have a jar on a server, and users should be able to develop extensions for it. Therefore the jars main class should be extended and some resources should be added to a second user created jar which will be loaded from another server or locally. Now I have problems accessing the resources (images) from the user loaded jars. Heres is the structure:

My Server:
  game.jar containing
    game.class
    images.class
    ...
    image1.png (...)

Local:
  user.jar containing:
    user.class extends game
    userimage.png

The extension is loaded via Greasemonkey, it modifies the "archive" attribute to "/home/username/user.jar, game.jar" and the "code" attribute to "user.class". The user should be able to overwrite already defined images. If the image does not exist in game.jar, it is loaded correctly from user.jar. But the images loaded early in the game are always loaded from the game.jar, others seem to be overwritten correctly by the user. Is there a way to make sure they are always loaded in the correct order? This might be because of some caching mechanism. Because Greasemonkey removes the game from the page, changes the archive and code and reinsert it, the game is loaded without a mod for a brief second. In that time, images are loaded as expected from game jar, but those are the ones not being overwritable by the user. But how to avoid it?

Another thing:
If I overwrite the "run" method in user.class, the game is unable to load any image at all. Not from the user.jar and not from the game.jar. Java doesn't find the image, as the URL object "getClass().getResource(imagename)" returns with null. I tried to overwrite the image.class, but that doesn't fix the problem, unless I overwrite every class from game.class involved into calling the image.class

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你没皮卡萌 2024-09-03 09:31:07

我不认为使用带有 标签的 Greasemonkey Monkey 不一定是最好的方法。也许您实际上应该让greasemonkey 脚本与您的小程序进行通信并告诉它需要什么?

当然,这就留下了如何让小程序等待脚本的问题,但只有当存在这样的脚本时......

I don't think having greasemonkey monkey with the <applet> tag is necessarily the best approach here. Perhaps you should actually have the greasemonkey script communicate with your applet and tell it what is wanted of it?

Of course, that leaves the question of how to have the applet wait for the script, but only when there is such a script...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文