How to embed jar in HTML
Asked Answered
G

3

5

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:

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

When I download the jar it runs fine, so I am certain the problem is only with the html embedding. Pleas help!

Also, I get the following error:

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

Gluttonous answered 23/9, 2011 at 15:59 Comment(2)
What does ImpViewer inherit from? Can you include it's class definition?Ornithomancy
Hi Sam, I don't know, I got handed without the source code. It's not inheriting from Applet that's for sure! Is there anyway to cram it into a website without it?Gluttonous
M
7
java.lang.ClassCastException: ImpViewer cannot be cast to java.applet.Applet

The 'applet' is not an applet.

BTW - nice UI. 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).


If the client insists on the GUI being crammed into a web site then (slap them for me &) try this hack.

/*
<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.
  2. It will only work at 720x564 px, unlike the java.awt.Frame which was resizable to any size. But then, your '100%' width/height was being a bit optimistic anyway. Some browsers will honour those constraints, others will not.
Marilou answered 23/9, 2011 at 16:20 Comment(1)
Hi Andrew, thanks for the complement, I didn't write the UI, it was handed to me by my client. And he just WANT to cram it into a website, so it's not my place to say no. Is there anyway that's possible?Gluttonous
O
1

It took a bit of effort, but your ImpViewer class has the following definition:

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

ImpViewer is NOT an Applet like it needs to be, but is instead an ImWindow. It should inherit from either Applet or perhaps ImApplet.

At either rate, Andrews idea of using Java Web Start is legit. The app you have looks more like a desktop app.

Ornithomancy answered 23/9, 2011 at 18:40 Comment(3)
You can see an example of Java Web Start at my old student website here: Sam's Tetris Page. See the Run Tetris Applet Using Java WebStart link. This is only to give you an example of what the user experience would be like.Ornithomancy
Alright, I'll just tell my client to use the JavaWS then. Thanks for the information.Gluttonous
Despite having included the 'shove it in an applet hack' in an edit above, I strongly recommend you take the JWS approach.Marilou
E
1

An Applet is a Java component which handles the right calls to show up embedded in a web page. The product you have (the JAR file) contains everything necessary to run the program; 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. 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.

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.

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

Endostosis answered 23/9, 2011 at 18:56 Comment(1)
+1 Perhaps whoever gave this to the user can make it compatible with applets. Looks like the app was made with "Impatica for PowerPoint 4.0" by "FACULTY-PC DAL". Also, apparently com.impatica.v402.ImPlayer.class extends Applet. However, I couldn't get anything to happen with it. :(Ornithomancy

© 2022 - 2024 — McMap. All rights reserved.