Hi,
this time, I would like to know the recommended way to distribute a
narwhal (very simple commonjs) script to be run as a standalone
application.
I can use a script with
java -cp path/to/narwhal/js.jar
org.mozilla.javascript.tools.shell.Main -e 'importPackage(
java.io,
java.util,javax.swing,
java.awt,java.awt.event);importClass(java.lang.System)' -f path/to/
narwhal/engines/rhino/bootstrap.js -f path/to/some/lib.js -f path/to/
myfile.js
is that correct?
How can I embed the same command line into Java? should I use the
scripting API or the Rhino API as shown, for instance, in
http://www.envjs.com/doc/guides #embed :
I'm not familiar with neither of them.
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.tools.shell.Global;
import org.mozilla.javascript.tools.shell.Main;
public class Test{
public static void main(String [] args){
Context cx = ContextFactory.getGlobal().enterContext();
cx.setOptimizationLevel(-1);
cx.setLanguageVersion(Context.VERSION_1_5);
Global global = Main.getGlobal();
global.init(cx);
Main.processSource(cx, "path/to/narwhal/engines/rhino/
bootstrap.js");
Main.processSource(cx, "path/to/some/lib.js");
Main.processSource(cx, "path/to/myfile.js");
}
}
I think the above solution is the prefered one, am I right?
Another question I have is about packages.json and jars. I haven't
been successful in putting a jar into a jars folder. It's never found
in the classpath! Could you provide a simple example?
say I do a "tusk init"...
I have my.jar in jars (containing org.example)
and in my js file I need to import org.example
var doit = function(){
importPackage(org.example);
...
}
For now I set the classpath the usual way, outside of packages.json.
Well, that's it!
Thanks for the project. I hope it's going to be active all year, and
happy new year for all Narwhal,Jack and other commonjs guys...
jg