Not able to resolve JSObject in a java applet project

13,864

Solution 1

The reason for this is that jfxrt.lib also has a class named JSObject. This JSObject does not have getWindow function defined while plugin.jar one has. If you change the dependency order of JAR and make java to resolve JSObject to plugin.jar then java is able to call getWindow function.

Following are the links to the javadocs of both the classes.Note that jfxrt one doesn't have getWindow defined.

http://docs.oracle.com/javafx/2/api/netscape/javascript/JSObject.html

http://www.oracle.com/webfolder/technetwork/java/plugin2/liveconnect/jsobject-javadoc/netscape/javascript/JSObject.html

Solution 2

I'm using IntelliJ and just encountered a similar issue.

What I think is happening is that jfxrt.jar and plugin.jar both have netscape.javascript.JSObject classes, but the two classes have different signatures. IntelliJ was adding the jars from jre/lib in alphabetical order to the classpath.

By telling IntelliJ not to add jfxrt.jar to the classpath I have been able to resolve my issue because I'm not using JavaFX.

What this points to is that JavaFX requires a different approach to using JSObject - I'm no expert (not even a beginner) at JavaFX but the following page looks useful and suggests to me that calling Javascript is done differently in JavaFX using WebEngine.executeScript(): https://blogs.oracle.com/javafx/entry/communicating_between_javascript_and_javafx

Solution 3

trying to call JSObject.getWindow(this) in the init method

The JSObject is typically not available until start() is called.

Solution 4

Did you import netscape.javascript.*;?

Solution 5

@deorvatsingh Here is the problem not with the netbeans the order you added the jar's. in JavaFx application jfxar.jar is visible first in netbeans cases thats the reason you are not able to get the scope for your JSObject.getWindow(this),

For executing this with netbeans and fxappication you first add the the plugin.jar then add jfxrt.jar to your appication then it will recognise.

Share:
13,864
deovrat singh
Author by

deovrat singh

Updated on July 23, 2022

Comments

  • deovrat singh
    deovrat singh almost 2 years

    I am trying to call JSObject.getWindow(this) in the init method of JApplet but it is not able to resolve the symbol getWindow.

    this problem is specifically happening with a javafx application project created through netbeans , getWindow is getting resolved if used in a java application project.

    I have also included the plugin.jar from path Java\jdk1.7.0_07\jre\lib.

    This is a javafx application project that I created in netbeans.

    • Andrew Thompson
      Andrew Thompson over 11 years
      "it is not able to resolve the symbol getWindow." Does that mean the same as 'returns null' or is it something else? Do you have a link to where we can visit the app. (& see it fail)? It might be helpful to also add an SSCCE of code that triggers the error - it should not take more than 2 dozen lines.
    • haylem
      haylem almost 11 years
      may be related: I've been building with Java 8 early builds, and at least since build 72 I also get a compilation failure for applets using this method (com.netscape.JSObject.getWindow).
    • jewelsea
      jewelsea almost 11 years
      I filed RT-30622 Not able to resolve JSObject.getWindow(this) in a java applet project against the JavaFX project to track this issue.
  • tchike
    tchike over 11 years
    I'm not familiar with NetBeans, you should check if you added plugin.jar to your classpath.
  • Seeta Somagani
    Seeta Somagani over 11 years
    Are you running the applet directly from your NetBeans or are you running from a browser? Maybe there's a difference there.
  • deovrat singh
    deovrat singh over 11 years
    Even in start it is not able to resolve, giving a compile error telling that getWindow symbol not found.It is able to recognize JSObject though. This is only happening when i am creating javafx application project in Netbeans,it is working fine with a java application project.