accessing the compiler with Rhino

55 views
Skip to first unread message

Tim Schaub

unread,
Nov 6, 2010, 3:33:20 PM11/6/10
to Closure Compiler Discuss
Hello-

I'm hoping to be able to drive the closure compiler from JavaScript by
running Rhino.

Wit the latest Closure compiler.jar (Nov 6, 2010) and Rhino 1.7R2
js.jar on my classpath, I get a wrapped NullPointerException when
trying to call compile (running the script here: https://gist.github.com/665609
with org.mozilla.javascript.tools.shell.Main*). The trace is below.

Is this due to conflicts between Rhino 1.7R2 and the 1.5R3, with
"heavy modifications" included with Closure? I see the jarjar'd
version and see that the modified version is renamespaced, so I was
guessing I wouldn't run in to conflicts.

Thanks for any tips,
Tim

* I also notice that if I try to run the script with
com.google.javascript.jscomp.mozilla.rhino.tools.shell.Main, I get all
sorts of NoClassDefFoundError.

calling compiler.compile(externs, inputs, options):

org.mozilla.javascript.WrappedException: Wrapped
java.lang.NullPointerException
at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:
1773)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:183)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:
247)
at org.mozilla.javascript.optimizer.OptRuntime.callN(OptRuntime.java:
86)
at org.mozilla.javascript.gen.c1._c0(Unknown Source)
at org.mozilla.javascript.gen.c1.call(Unknown Source)
at
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:
398)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:
3065)
at org.mozilla.javascript.gen.c1.call(Unknown Source)
at org.mozilla.javascript.gen.c1.exec(Unknown Source)
at org.mozilla.javascript.tools.shell.Main.evaluateScript(Main.java:
564)
at
org.mozilla.javascript.tools.shell.Main.processFileSecure(Main.java:
486)
at org.mozilla.javascript.tools.shell.Main.processFile(Main.java:452)
at org.mozilla.javascript.tools.shell.Main.processSource(Main.java:
443)
at org.mozilla.javascript.tools.shell.Main.processFiles(Main.java:
196)
at org.mozilla.javascript.tools.shell.Main$IProxy.run(Main.java:117)
at org.mozilla.javascript.Context.call(Context.java:515)
at org.mozilla.javascript.ContextFactory.call(ContextFactory.java:
507)
at org.mozilla.javascript.tools.shell.Main.exec(Main.java:179)
at org.mozilla.javascript.tools.shell.Main.main(Main.java:157)
Caused by: java.lang.NullPointerException
at com.google.javascript.jscomp.Compiler.newTracer(Unknown Source)
at com.google.javascript.jscomp.Compiler.compile(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161)
... 18 more

Tim Schaub

unread,
Nov 6, 2010, 3:51:45 PM11/6/10
to Closure Compiler Discuss
It looks like a recent change in Rhino fixes the problem:
https://github.com/earl/rhino-mirror/commit/23f2541cc012a2f17f6f95e107827e4b0a8798b7

Thanks Hannes for pointing that out to me.

Tim

Alex Objelean

unread,
Nov 7, 2010, 2:39:13 AM11/7/10
to Closure Compiler Discuss
I have managed to use latest version of closure with rhino 1.7-rc2
version without any problems. The only thing to mention is that I have
created a custom distributiom of closure free of rhino. You can find
it here: http://code.google.com/p/wro4j

Alex
Reply all
Reply to author
Forward
0 new messages