admin管理员组

文章数量:1122832

I know applets are no longer formally supported. I have some legacy code that can still run using IE 11/Edge in compatibility mode. I can also run applets in any browser using Webswing.

My applets use netscape.javascript.JSObject to perform live connect to the page's JavaScript.

I can compile with Java 11, but in Java 17, method netscape.javascript.JSObject.getWindow() has been removed. If I try to compile an applet that uses netscape.javascript.JSObject.getWindow() with Java 17, I get a compilation error. Here's a sample applet and the compilation error I get:

Sample applet:

package your.package.name;

import javax.swing.JApplet;

public class SimpleApplet extends JApplet {
    private static final long serialVersionUID = 1L;

    public void init() {
        System.out.println("SimpleApplet.init()");
        netscape.javascript.JSObject win = netscape.javascript.JSObject.getWindow(this);
    }
    
    public void start() {
        System.out.println("SimpleApplet.start()");
    }
    
    public void destroy() {
        System.out.println("SimpleApplet.destroy()");
    }
}

Compiling with command: "C:\Program Files\Java\jdk-17\bin\javac.exe" "C:\Users\userId\your\package\name\SimpleApplet.java"

Yields this output:

SimpleApplet.java:5: warning: [removal] JApplet in javax.swing has been deprecated and marked for removal
public class SimpleApplet extends JApplet {
                                  ^
SimpleApplet.java:10: error: cannot find symbol
                netscape.javascript.JSObject win = netscape.javascript.JSObject.getWindow(this);
                                                                               ^
  symbol:   method getWindow(SimpleApplet)
  location: class JSObject
1 error
1 warning

I know the netscape.javascript.JSObject.getWindow() method has been removed, so I figured I'd add jaws.jar to the classpath (note that jaws.jar is basically the same as plugin.jar). Compiling with jaws.jar as follows: "C:\Program Files\Java\jdk-17\bin\javac.exe" -cp "C:\Users\userId\jaws.jar" "C:\Users\userId\your\package\name\SimpleApplet.java"

Yields this identical output:

SimpleApplet.java:5: warning: [removal] JApplet in javax.swing has been deprecated and marked for removal
public class SimpleApplet extends JApplet {
                                  ^
SimpleApplet.java:10: error: cannot find symbol
                netscape.javascript.JSObject win = netscape.javascript.JSObject.getWindow(this);
                                                                               ^
  symbol:   method getWindow(SimpleApplet)
  location: class JSObject
1 error
1 warning

It seems that the compiler is not looking at my jaws.jar. If he did, he'd find the netscape.javascript.JSObject.getWindow() method.

Can I compile with Java 17? Is there a way to force the compiler to use the jaws.jar implementation of netscape.javascript.JSObject?

A side note: The test applet above is not flagged with errors in eclipse as long as I have the jaws.jar listed before Java 17 (in Project Properties->Java Build Path: Order and Export tab). If I move Java 17 above jaws.jar, then the IDE flags getWindow() as an error. If eclipse can handle Java 17, then I assume javac should be able to, too.

本文标签: