I have a class "one.two.Foo" in a jar file named "foo.jar". From the
documentation, I think I should be able to do the following:
var url = new java.net.URL("file:///path/to/foo.jar");
var loader = new java.net.URLClassLoader([ url ]);
var pks = new Packages(loader);
var foo = pks.one.two.Foo();
However, this doesn't work. I'm getting a NullPointerException:
java.lang.NullPointerException
at
org.mozilla.javascript.ScriptableObject.getTopLevelScope(ScriptableObject.java:
1514)
at
org.mozilla.javascript.ScriptRuntime.setObjectProtoAndParent(ScriptRuntime.java:
3291)
at
org.mozilla.javascript.NativeJavaPackage.getPkgProperty(NativeJavaPackage.java:
166)
at
org.mozilla.javascript.NativeJavaPackage.get(NativeJavaPackage.java:
105)
at
org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:
1575)
at
org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:
1397)
at
org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:
1383)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:
3054)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:
2484)
at
org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:
162)
at
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:
401)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:
3003)
at
org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:
173)
...
On the other hand, the following does work, so I know that the VM is
able to load the class:
var url = new java.net.URL("file:///path/to/foo.jar");
var loader = new java.net.URLClassLoader([ url ]);
var cl = loader.loadClass("one.two.Foo");
var foo = cl.newInstance();
This is taking place in a very simple embedding of Rhino in a servlet.
Any thoughts?
-Jon
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino