直接从 jar 文件启动 Java 小程序 [英] Starting Java applet directly from jar file

查看:30
本文介绍了直接从 jar 文件启动 Java 小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

Internet 上的示例表明此小程序标记:

Samples on the Internet suggest this applet tag:

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

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

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

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

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

必须如何制定小程序标签才能从 jar 文件的内部启动小程序类?

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

推荐答案

问题是 Java 控制台正在缓存以前的坏 jar.在 Java 控制台中清除缓存后,代码的第一个版本运行良好.

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">

这篇关于直接从 jar 文件启动 Java 小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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