如何为当今的浏览器(小程序、嵌入、对象)部署一个 Java 小程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/985754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 21:53:35  来源:igfitidea点击:

How to deploy a java applet for today's browsers (applet, embed, object)?

javadeploymentapplet

提问by Michael Siebert

How do i deploy a java applet for modern browsers? I know there are somehow 3 possibilities but nobody tells me which one to prefer and how to use them.

如何为现代浏览器部署 Java 小程序?我知道有 3 种可能性,但没有人告诉我更喜欢哪一种以及如何使用它们。

Does somebody have any resources on that? i cant find any :(

有人有这方面的资源吗?我找不到任何:(

采纳答案by coobird

There is a section in The Java Tutorialstitled Using applet, object and embed Tagswhich addresses the issue.

The Java Tutorials 中有一个标题为Using applet, object and embed Tags 的部分解决了这个问题。

From the General Considerations:

一般考虑

Deploying Applets on the Internet Versus an Intranet

When deploying applets:

  • Use the applettag if the Web page is accessed through the Internet.
  • Use the objector embedtag if the Web page is accessed through an Intranet.

Deploying Applets for Specific Browsers

When deploying applets:

  • For Internet Explorer only, use the objecttag.
  • For the Mozilla family of browsers only, use the embedtag.

If you must deploy an applet in a mixed-browser environment, follow the guidelines in the section Deploying Applets in a Mixed-Browser Environment.

在 Internet 与 Intranet 上部署 Applet

部署小程序时:

  • applet如果网页是通过 Internet 访问的,请使用该标签。
  • 如果网页是通过 Intranet 访问的,请使用objectembed标记。

为特定浏览器部署小程序

部署小程序时:

  • 仅对于 Internet Explorer,使用 object标记。
  • 仅对于 Mozilla 系列浏览器,请使用 embed标记。

如果您必须在混合浏览器环境中部署小程序,请遵循在混合浏览器环境中部署小程序部分中的指南。

It should be noted that the applettag has been deprecated, so it's probably not desirable to use that tag. (More information on the applettag from the W3C)

应该注意的是,该applet标签已被弃用,因此可能不希望使用该标签。(有关appletW3C 标签的更多信息

(Note: Links have been updated from the previous edit to link to The Java Tutorials.)

(注意:链接已从之前的编辑更新为链接到 Java 教程。)

回答by Robert Munteanu

If you can target Java 6 update 10 or better, you can simplify your life:

如果您可以针对 Java 6 更新 10 或更高版本,则可以简化您的生活

<script src="http://java.com/js/deployJava.js"></script>
<script>
    var attributes = {codebase:'http://java.sun.com/products/plugin/1.5.0/demos/jfc/Java2D',
                      code:'java2d.Java2DemoApplet.class',
                      archive:'Java2Demo.jar',
                      width:710, height:540} ;
    var parameters = {fontSize:16} ;
    var version = '1.6' ;
    deployJava.runApplet(attributes, parameters, version);
</script>

回答by Marko

You might consider using Java Web Start instead of an applet if you are making an application. Applets are used only if are creating something that has to be shown in a browser.

如果您正在制作应用程序,您可能会考虑使用 Java Web Start 而不是小程序。只有在创建必须在浏览器中显示的内容时才使用小程序。

回答by Rob Whelan

Use deployJava.js -- even if you AREN'T targeting only 1.6 and above. I've been using it for more than a year, with applets that still support even the MSJVM (Java 1.1).

使用 deployJava.js —— 即使您的目标不是 1.6 及更高版本。我已经使用它一年多了,它的小程序仍然支持 MSJVM (Java 1.1)。

There are plenty of features that aren't available in the script for older JREs, but it's still quite useful!

有很多功能在旧 JRE 的脚本中不可用,但它仍然非常有用!

回答by Anton K

Well, be aware that deployJava.js is designed to be called at document load time. So if you insert applet dynamically, upon an event, after DOM has been constructed, you're kinda out of luck with this new standard approach. We had to use the object/embed/noembed construct.

请注意,deployJava.js 旨在在文档加载时调用。因此,如果您在构建 DOM 之后在事件上动态插入小程序,那么这种新的标准方法就有点不走运了。我们不得不使用 object/embed/noembed 结构。

Edit: Oh, someone found a better way for this, but this required manual altering of SUN's original deployJava.js, please see the link below: Java Plug-In - Important addition to deployJava.js

编辑:哦,有人为此找到了更好的方法,但这需要手动更改 SUN 的原始 deployJava.js,请参阅以下链接: Java 插件 - deployJava.js 的重要补充

回答by Terje Dahl

deployJava.js has many serious lacks.

deployJava.js 有很多严重的不足。

Read my write-up on deployJava.json Oracles Java-forum.

在 Oracles Java 论坛阅读我关于 deployJava.js 的文章。

I would love to start an open source project on this, but I have no experience on starting or doing anything open source. Anybody care to help me get one started? (Preferrably on BitBucketusing Mercurial.) If so, comment on this, and contact me directly.

我很想在这方面启动一个开源项目,但我没有启动或做任何开源项目的经验。有人愿意帮我入门吗?(最好在BitBucket 上使用Mercurial。)如果是这样,请对此发表评论,并直接与我联系。

回答by Anon

The below should work cross browser:-

以下应该跨浏览器工作: -

<p>
<object type="application/x-java-applet"
    name="accessName" width="300" height="200">
    <param name="code" value="className" />
    <param name="archive" value="jarName.jar" />
    <param name="scriptable" value="true" />
    <param name="mayscript" value="true" />
</object>
</p>

In my tests both IE8 and FF5 required the "type" attribute. Any object classid attribute caused Firefox to fail. The mayscript param will be ignored by Java plugins after 1.6.0.10. The scriptable param is still required according to javadocs 1.6.0.21. In a test with 1.6.0.24 for a signed applet, IE8 called it OK from JS without scriptable being set true.

在我的测试中,IE8 和 FF5 都需要“type”属性。任何对象的 classid 属性都会导致 Firefox 失败。在 1.6.0.10 之后,Java 插件将忽略 mayscript 参数。根据 javadocs 1.6.0.21,脚本化参数仍然是必需的。在使用 1.6.0.24 对签名小程序进行的测试中,IE8 从 JS 调用它可以,而无需将 scriptable 设置为 true。