Dev : Extensions : Example Code : Calling Java from Javascript

From MozillaZine Knowledge Base

(Difference between revisions)

Revision as of 23:17, 26 October 2005

This page is currently notes of what I had to do to call Java from Javascript.

Here's an example from a blog:

   var cl = new

   var aClass ="HelloWorld", true, cl);
   var aStaticMethod = aClass.getMethod("getGreeting", []);
   var greeting = aStaticMethod.invoke(null, []);

In order to write to the file system, I had to add this to the javascript code: java.lang.System.setSecurityManager(null); I could read a jar from the filesystem without a problem.

Calling showJavaConsole is very useful for debugging:

        var jvm = Components.classes[";1"].getService(Components.interfaces.nsIJVMManager);