Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with generated .class

8 views
Skip to first unread message

Alessandro Zucchi

unread,
Jan 4, 2008, 11:11:06 AM1/4/08
to dev-tech-js-...@lists.mozilla.org
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

Norris Boyd

unread,
Jan 7, 2008, 10:15:03 AM1/7/08
to
On Jan 4, 11:11 am, "Alessandro Zucchi"

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

alessand...@gmail.com

unread,
Jan 8, 2008, 5:35:28 AM1/8/08
to

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

Norris Boyd

unread,
Jan 8, 2008, 9:16:58 AM1/8/08
to

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

0 new messages