You can use Rhino's CommonJS support by implementing org.mozilla.javascript.commonjs.module.Require, which can be done inside JS. I am using this in Myna[1] and you can see how I'm doing it here[2]. Basically you need to let Rhino know how to resolve CommonJS classpaths, and it takes care of the rest.
Note: Rhino's CommonJS support is only implemented in CVS right now, so you'll need to build from CVS. if you are feeling lazy you can grab my js.jar build from [3]. [1]:http://www.mynajs.org [2]:http://code.google.com/p/myna/source/browse/trunk/1.0/web/shared/ js/libOO/CommonJS.sjs?spec=svn109&r=109 [3]:http://myna.googlecode.com/svn-history/r109/trunk/1.0/jars/js.jar ---------------------------------------------------------- Mark Porter Myna JavaScript Application Server Easy server-side JS on a Java platform http://www.mynajs.org On May 24, 6:18 am, Daryl Stultz <[email protected]> wrote: > On Sun, May 23, 2010 at 12:22 PM, Ivana <[email protected]> wrote: > > Hi, > > > I need to define variables and functions in one javascript file, and than > > include this file into another javascript file and use them. Is that > > possible (even if is needed to use java interface)? > > I use an approach similar to Dan's however I'd like to replace it with > "require". There's been some work done here to support the "require()" > function, I don't know much of the details, maybe someone else here can > cover it. > > -- > Daryl Stultz > _____________________________________ > 6 Degrees Software and Consulting, > Inc.http://www.6degrees.comhttp://www.opentempo.com > mailto:[email protected] _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
