On Jan 8, 5:35 am, [EMAIL PROTECTED] wrote:
> On 7 Gen, 16:15, Norris Boyd <[EMAIL PROTECTED]> wrote:
>
> > On Jan 4, 11:11 am, "Alessandro Zucchi"
>
> > <[EMAIL PROTECTED]> wrote:
> > > Hi all,
>
> > > I' ve 2 js files as follow:
>
> > > exec.js
> > > print (somma(3,4))
> > > java.lang.System.out.println("hi, mom!");
>
> > > stringUtil.js
> > > function somma(a,b)
> > > {
> > > var totale=a+b;
> > > return totale;}
>
> > > If I use the shell as follow:
> > > java -jar js.jar -f ZZZ\stringUtil.js ZZZ\exec.js
> > > all runs OK and obtain
> > > 7
> > > hi, mom!
>
> > > If I generate the correspondly .class file using
> > > java -classpath js.jar org.mozilla.javascript.tools.jsc.Main ZZZ\*.js
> > > and try to run:
> > > java -classpath "..\js.jar;." exec
> > > I get the following error:
>
> > > C:\Lavori\zrt\rhino1_6R7\ZZZ>java -classpath "..\js.jar;." exec
> > > Exception in thread "main" org.mozilla.javascript.EcmaError:
> > > ReferenceError: "somma"
> > > at
> > > org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:33
> > > at
> > > org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:33
> > > at
> > > org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:341
> > > at
> > > org.mozilla.javascript.ScriptRuntime.getNameFunctionAndThis(ScriptRuntime
> > > at
> > > org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:95)
> > > at exec._c0(Unknown Source)
> > > at exec.call(Unknown Source)
> > > at
> > > org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:393)
> > > at
> > > org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2834)
> > > at exec.call(Unknown Source)
> > > at exec.exec(Unknown Source)
> > > at
> > > org.mozilla.javascript.optimizer.OptRuntime$1.run(OptRuntime.java:252)
> > > at org.mozilla.javascript.Context.call(Context.java:577)
> > > at org.mozilla.javascript.Context.call(Context.java:499)
> > > at
> > > org.mozilla.javascript.optimizer.OptRuntime.main(OptRuntime.java:240)
> > > at exec.main(Unknown Source)
>
> > > How can I resolve this error ??? Where I make a mistake ???
> > > Thanks in advance.
>
> > > Alex
>
> > The problem is that loading "exec" doesn't force loading "stringUtil".
> > Try using the shell to explicitly load the classes:
>
> > [rhino] cat ZZZ/stringUtil.js
> > function somma(a,b)
> > {
> > var totale=a+b;
> > return totale;}
>
> > [rhino] cat ZZZ/exec.js
> > print (somma(3,4))
> > java.lang.System.out.println("hi, mom!");
> > [rhino] java -classpath build/rhino1_7R1pre/js.jar
> > org.mozilla.javascript.tools.jsc.Main ZZZ/*.js
> > [rhino] java -classpath build/rhino1_7R1pre/js.jar:.
> > org.mozilla.javascript.tools.shell.Main -f ZZZ/stringUtil.class -f ZZZ/
> > exec.class
> > 7
> > hi, mom!
> > [rhino]
>
> > --N
>
> Thank you Norris,
> in this way all runs.
> I thougth to be able to run the compiled class outside the shell.
> Probably this runs only for js not linked one to another. "What a
> pity !!!" .... it was better not use directly the shell to run my app
> Bye
Yes, the issue is the one piece of JavaScript depending on another.
Given JavaScript's dynamic nature we didn't want to compile in
explicit dependencies into the generated class files.
The shell is not strictly required; if you create a scope and then
load the generated classes as org.mozilla.javascript.Script instances
and then call their exec() methods in turn on the same scope you
should get the behavior you desire.
--N
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino