直接从 jar 文件启动 Java applet

发布于 2024-08-28 08:49:45 字数 1362 浏览 2 评论 0原文

目标是从 jar 文件运行小程序。

问题是该小程序似乎只想从分解的 jar 文件运行。

Internet 上的示例建议使用此小程序标记:

  <applet code="com.blabla.MainApplet"
          archive="applet.jar"
          width="600" height="600">

这甚至不会尝试查找 jar 文件,并会失败:

Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/helloWord/com/blabbla/MainApplet.class
 at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
 at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
 at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 ... 7 more

将代码库而不是 archive 属性设置为 jar 文件。看起来好一点了。然而,JVM 并没有意识到它必须打开 jar 文件:

  <applet code="com.blabla.MainApplet"
          codebase="applet.jar"
          width="600" height="600">


Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/helloWord/applet.jar/com/blabbla/MainApplet.class
 at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
 at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
 at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 ... 7 more

必须如何制定 applet 标记才能从 jar 文件的内部启动 applet 类?

The goal is to have an applet run from a jar file.

The problem is that the applet only seems to want to run from an exploded jar file.

Samples on the Internet suggest this applet tag:

  <applet code="com.blabla.MainApplet"
          archive="applet.jar"
          width="600" height="600">

This will not even try to look in the jar file and fails with:

Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/helloWord/com/blabbla/MainApplet.class
 at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
 at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
 at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 ... 7 more

Setting the codebase instead of the archive attribute to the jar file. Looks a bit better. However, the JVM does not realize that it has to open the jar file:

  <applet code="com.blabla.MainApplet"
          codebase="applet.jar"
          width="600" height="600">


Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/helloWord/applet.jar/com/blabbla/MainApplet.class
 at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
 at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
 at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 ... 7 more

How does the applet tag have to be formulated to start an applet class from inside of a jar file?

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

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

发布评论

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

评论(1

别把无礼当个性 2024-09-04 08:49:45

问题是 Java 控制台正在缓存以前的坏 jar。一旦在 Java 控制台中清除了缓存,第一个版本的代码就可以正常工作。

<applet code="com.blabla.MainApplet"
          archive="applet.jar"
          width="600" height="600">

The problem was that the Java console was caching previous bad jars. Once the cache was cleared in the Java console, the first version of the code worked fine.

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