Hi, I'm trying to run a very simple java program from a Firefox extension I'm making but I've run into a brickwall and just can't get it to work. I'm a complete beginner in java and don't know much javascript so I've copied and pasted code from around the net to get where I am now. I'm sure I'm just making some stupid error at some step.
In order to work out what I'm misunderstanding/doing wrong I'd be really grateful if someone could show me how to get it to work using a very basic example:
Say I have a .java file taken from the sun pages:
/**
* The HelloWorldApp class implements an application that
* simply displays "Hello World!" to the standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); //Display the string.
}
}
So I stick it into a jar using:
jar.exe cvfe HelloWorldApp.jar HelloWorldApp.class HelloWorldApp.class
I then place it directly on my C: drive.
In the javascript of my firefox extension I have code copied and pasted from https://developer.mozilla.org/en/Java_in_Firefox_Extensions:
var urlClasz = java.lang.Class.forName("java.net.URL");
var urlArray = java.lang.reflect.Array.newInstance(urlClasz,1);
urlArray[0] = new java.net.URL('file:///C:/HelloWorldApp.jar');
var cl = java.net.URLClassLoader.newInstance(urlArray);
var aClass = java.lang.Class.forName("HelloWorldApp", true, cl);
var aStaticMethod = aClass.getMethod("HelloWorldApp", []);
var greeting = aStaticMethod.invoke(null, []);
This seems to start java but then only gives me the error:
"Error: uncaught exception: Error calling method on NPObject! [plugin exception: java.lang.ClassNotFoundException: HelloWorldApp]."
I would be infinitely grateful if someone could show me the code I would use in this situation to run the HelloWorldApp. If I could get it working in this basic situation I'm sure I could work it out from there.
Thank you very, very much!!