简体   繁体   English

如何在HTML中嵌入jar

[英]How to embed jar in HTML

There are a lot of resources on this already but I just can't seem to get it to work. 这已经有很多资源,但我似乎无法让它发挥作用。 What am I doing wrong? 我究竟做错了什么? The jar file is at: jar文件位于:

http://www.alexandertechniqueatlantic.ca/multimedia/AT-web-presentation-imp.jar http://www.alexandertechniqueatlantic.ca/multimedia/AT-web-presentation-imp.jar

And the code I am using to embed is: 我用来嵌入的代码是:

<APPLET ARCHIVE="multimedia/AT-web-presentation-imp.jar" 
        CODE="ImpViewer.class" 
        WIDTH=100% 
        HEIGHT=100%>
</APPLET>

The test page I am using is at: 我正在使用的测试页面位于:

http://www.alexandertechniqueatlantic.ca/test.php http://www.alexandertechniqueatlantic.ca/test.php

When I download the jar it runs fine, so I am certain the problem is only with the html embedding. 当我下载jar它运行正常,所以我确定问题只有html嵌入。 Pleas help! 请帮助!

Also, I get the following error: 另外,我收到以下错误:

java.lang.ClassCastException: ImpViewer cannot be cast to java.applet.Applet java.lang.ClassCastException:无法将ImpViewer强制转换为java.applet.Applet

java.lang.ClassCastException: ImpViewer cannot be cast to java.applet.Applet

The 'applet' is not an applet. 'applet' 不是 applet。

BTW - nice UI. BTW - 很棒的用户界面。 Like the way the red splash fades in to the 'Welcome Introductory Workshop' page. 就像红色飞溅进入“欢迎入门工作坊”页面一样。 Very smooth. 很顺利。

Launch it from a link using Java Web Start (& please don't try and cram such a beautiful UI into a web page). 使用Java Web Start从链接启动它(请不要尝试将如此漂亮的UI填充到网页中)。


If the client insists on the GUI being crammed into a web site then (slap them for me &) try this hack. 如果客户端坚持要将GUI塞进网站然后(为我拍打它们)尝试这个黑客攻击。

/*
<APPLET 
    ARCHIVE="AT-web-presentation-imp.jar" 
    CODE="ImpViewerApplet" 
    WIDTH=720 
    HEIGHT=564>
</APPLET>
*/
import java.awt.*;
import java.applet.*;
import java.util.*;

public class ImpViewerApplet extends Applet {

    public void init() {
        setLayout(new BorderLayout());
        Window[] all = Window.getWindows();
        ArrayList<Window> allList = new ArrayList<Window>();
        for (Window window : all) {
            allList.add(window);
        }
        String[] args = {};
        ImpViewer iv = new ImpViewer(); 
        iv.main(args);

        all = Window.getWindows();
        for (Window window : all) {
            if (!allList.contains(window) && window.isVisible()) {
                if (window instanceof Frame) {
                    Frame f = (Frame)window;
                    Component[] allComp = f.getComponents();
                    Component c = f.getComponents()[0];
                    f.remove(c);
                    f.setVisible(false);
                    add(c);
                    validate();
                }
            }
        }
    }
}

The emphasis is on the word 'hack'. 重点是“黑客”这个词。

  1. The Frame will flash onto screen before disappearing. Frame会在消失之前闪烁到屏幕上。
  2. It will only work at 720x564 px, unlike the java.awt.Frame which was resizable to any size. 它只能在720x564像素下工作,不像java.awt.Frame可以调整到任何大小。 But then, your '100%' width/height was being a bit optimistic anyway. 但是,无论如何,你的'100%'宽度/高度有点乐观。 Some browsers will honour those constraints, others will not. 有些浏览器会尊重这些限制,有些则不会。

It took a bit of effort, but your ImpViewer class has the following definition: 需要花费一些精力,但您的ImpViewer类具有以下定义:

public class ImpViewer extends ImWindow
  implements Printable, Runnable
{
   [...]

ImpViewer is NOT an Applet like it needs to be, but is instead an ImWindow . ImpViewer不是一个像它需要的Applet ,而是一个ImWindow It should inherit from either Applet or perhaps ImApplet . 它应该从AppletImApplet继承。

At either rate, Andrews idea of using Java Web Start is legit. 无论哪种速度,安德鲁斯使用Java Web Start的想法都是合法的。 The app you have looks more like a desktop app. 您拥有的应用程序看起来更像桌面应用程序。

An Applet is a Java component which handles the right calls to show up embedded in a web page. Applet是一个Java组件,它处理显示嵌入在网页中的正确调用。 The product you have (the JAR file) contains everything necessary to run the program; 您拥有的产品(JAR文件)包含运行程序所需的一切; however, it does not have the correct interface (the applet) for running that program embedded in a web page. 但是,它没有正确的界面(小程序)来运行嵌入在网页中的程序。

Talk to the author of the product (of if that author is not available, look for documentation) and see if a applet interface is available. 与产品的作者交谈(如果该作者不可用,请查找文档)并查看applet接口是否可用。 Perhaps it is only a matter of using a different class name. 也许这只是使用不同类名的问题。 If it looks like such an interface is not available, then no one has done the necessary work to make it "embeddable" in a web page. 如果看起来这样的界面不可用,那么没有人做过必要的工作来使其“嵌入”在网页中。 Without knowing your product in more detail, it's not easy to determine if the effort to create an Applet interface into the product is easy or not. 如果不更详细地了解您的产品,就很难确定在产品中创建Applet界面的努力是否容易。

If you don't have the source code, then the amount of effort to develop an Applet interface to what you have is even greater than the unknown amount of effort it would have been with the source code. 如果您没有源代码,那么开发Applet接口所需的工作量甚至大于源代码所需的未知工作量。

There are a few products that do allow applications to be viewed and controlled from a web browser, even when the application in question wasn't designed to be embedded in a web page. 有一些产品允许从Web浏览器查看和控制应用程序,即使有问题的应用程序未设计为嵌入网页中。 These products tend to be expensive and proprietary; 这些产品往往价格昂贵且专有; but, if it is truly mission-critical (and if it makes enough money) then the expense and effort might be bearable. 但是,如果它真的是关键任务(并且如果它赚足够的钱)那么费用和努力可能是可以承受的。 With such a solution, the web browser actually opens a window into a configured "application server" which launches the application in full screen mode every time the connection is established. 有了这样的解决方案,Web浏览器实际上打开一个窗口,进入配置的“应用程序服务器”,每次建立连接时都以全屏模式启动应用程序。 Yes, it is an odd architecture; 是的,这是一个奇怪的架构; however, such an odd architecture exists purposefully as that's really the only way possible to do some things when the application can't run in other environments. 然而,这种奇怪的体系结构是有目的地存在的,因为当应用程序无法在其他环境中运行时,这是实现某些事情的唯一方法。

Look to Citrix for such a solution in the event that you can afford it (remember there's extra windows licenses involved) and you can tolerate it's performance and quirks. 在您可以负担得起的情况下,请向思杰寻求这样的解决方案(请记住,还有额外的Windows许可证),您可以容忍它的性能和怪癖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM