Packaging Narwhal and packages in a jar

2 views
Skip to first unread message

Matthew Taylor

unread,
Aug 16, 2010, 11:00:48 AM8/16/10
to Narwhal and Jack
I have a CommonJS package full of modules that currently runs in
Narwhal and RingoJS. The package provides an API that I would like to
make available to Java applications. I'd like to figure out how I can
compile the package and package it along with the Narwhal classes I'll
need inside a jar that I can just include in other Java projects.

Do I need to manually invoke the rhino compiler for my package and the
modules inside? Then how do I know what Narwhal classes I need to
include in the jar for the environment to work?

What the package exports is the API I want to provide for my Java
application.

For example, the main module that exposes "exports" might do this:

exports.toUpperCase = function(str) {...};
exports.toLowerCase = function(str) {...};

And I want to provide a Java API with this jar where I can do this:

new MyNarwhalPackageEnvironment().toUpperCase('not upper yet');

Am I going about this in the wrong way?

Many thanks,
Matt Taylor
dangertree.net

Matthew Taylor

unread,
Aug 18, 2010, 10:55:59 AM8/18/10
to Narwhal and Jack
I'm still struggling with this, and it would help me out greatly if someone could give me an idea how to do this. 

Right now I'm trying to do something simple, like run the fibonacci example from a java context.


I need to figure out how to compile this and everything in Narwhal that I need into a jar so I can run it from within another Java application.

I've found instructions on using the rhino compiler (https://developer.mozilla.org/en/Rhino_JavaScript_Compiler), and that seems easy enough to generate classes from JS files, but I don't see anywhere this is automated to compile all of Narwhal. I guess my next step is to create a script that runs this compiler and finds all JS files in the Narwhal environment and dumps the classes into an output directory. But even then, how are the JS files packaged? I used Rhino compiler to compile narwhal.js, for example, then I decompiled it and found that it exists in the default package because that is the default for the Rhino compiler. Will I need to specify certain packages for certain Narwhal scripts?

I guess I'll need some type of runner that can specify what JS script is the main application to be run.

Thanks ahead of time for any tips you can give me.

\m/ (>.<) \m/
matthew taylor




--
You received this message because you are subscribed to the Google Groups "Narwhal and Jack" group.
To post to this group, send email to narw...@googlegroups.com.
To unsubscribe from this group, send email to narwhaljs+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/narwhaljs?hl=en.


Hannes Wallnoefer

unread,
Aug 18, 2010, 11:46:32 AM8/18/10
to narw...@googlegroups.com
Hi Matthew,

2010/8/18 Matthew Taylor <rhyo...@gmail.com>:

Java is a statically typed language, and needs a definition of the
MyNarwhalPackageEnvironment class or interface at compile time. It's
not possible to define a Java class or interface in Rhino (although
it's possible to subclass or implement one). The closest you'll get is
some generic invocation interface, like

engine.invoke(module, function, args...)

Hope that helps,
Hannes

Kris Kowal

unread,
Aug 18, 2010, 2:46:51 PM8/18/10
to narw...@googlegroups.com
On Mon, Aug 16, 2010 at 8:00 AM, Matthew Taylor <rhyo...@gmail.com> wrote:

We haven't put anything in place to make Narwhal modules available
from within Java, so this would be an area where you would need to do
significant invention. As Hannes points out, you could make such an
API that uses Rhino's types. However, Narwhal is designed to initiate
itself from the shell. You would need to construct a Narwhal on Java
bootstrapping, which would need to prepare environment variables,
evaluate the narwhal.js script, and pass a suitable engine object to
the returned function.

Kris Kowal

Reply all
Reply to author
Forward
0 new messages