importClass(HelloWorld);
var hw = new HelloWorld();
java.lang.System.out.println(java.lang.Class.forName('HelloWorld'));
Exception in thread "main" org.mozilla.javascript.EcmaError:
ReferenceError: "HelloWorld" is not defined. at
org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3
654)
Why can't I import in a class that is not part of Java?
Best,
Clifton Sothoron
1. The classpath is not used when you execute a jar file, in case you
run Rhino like that. You need to put the class in your
bootclasspath instead.
2. You will find you HelloWorld class inside the Packages top-level
object.
For example:
[martin@elsa ~]$ cat<<EOF> HelloWorld.java
> public class HelloWorld {
> public HelloWorld() {}
> }
> EOF
[martin@elsa ~]$ cat<<EOF> HelloWorld.js
> importClass(Packages.HelloWorld);
> var hw = new HelloWorld();
> java.lang.System.out.println(java.lang.Class.forName('HelloWorld'));
> EOF
[martin@elsa ~]$ javac HelloWorld.java
[martin@elsa ~]$ java -Xbootclasspath/p:. -jar ~/source/external/JavaScript/rhino/build/rhino1_7R3pre/js.jar HelloWorld.js
class HelloWorld
[martin@elsa ~]$
--
---- Martin Blom --------------------------- mar...@blom.org ----
Eccl 1:18 http://martin.blom.org/