Subj : Re: Calling a compiled script with arguments To : redcoat From : Igor Bukanov Date : Mon Dec 20 2004 12:19 pm redcoat wrote: >..but can't see a way to do the last step! > > Once it's compiled etc., I can open a stream to it, but how do I > instantiate it as a Script object from within my Java code so I can > then execute it? I'm guessing there's a method I'm not seeing...? After you compile JS, you get a set of class files. To load them as classes you need to create ClassLoader and define classes there. You can either create you own or use Context.createClassLoader which gives you an instance of GeneratedClassLoader where you can call GeneratedClassLoader.defineClass to load the classes. Regards, Igor > > David > > Igor Bukanov wrote: > >>redcoat wrote: >> >>>If the script is already compiled in a file, is there a way to > > "load" > >>>it and then execute it with different variables? >> >>You can compile script to JVM class file using either JS compiler > > tool, > >>http://www.mozilla.org/rhino/jsc.html or via ClassCompiler, >> > > http://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/optimizer/ClassCompiler.html > > >>, from Java program. Then you can load the class and instantiate it >>which gives Script instance that you can use as in the above example. >> >>Regards, Igor > > .