直接从 jar 文件启动 Java applet
目标是从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是 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.