Avatar.js and Project Avatar

7.7k views Asked by At

In the context of Java 8 and Nashorn I see two projects being regularly mentioned.

Avatar.js and Project Avatar

What is the relation of these projects?

Avatar.js has very little documentation. As far as I gathered it offers the possibility to execute node applications on the JVM.

Project Avatar seems to build on Avatar.js. However the scope seems to be to provide an alternative Web-Framework for Java EE 7. Is it also possible to execute node programs (like i.e. grunt) with Project Avatar?

3

There are 3 answers

2
Johann On BEST ANSWER

Update: Project Avatar was officially halted 2015-02-12.

Avatar.js is the open-source version of what was informally called 'node.jar' (See this post from the avatar-js mailing list). In other words, it is a NodeJS-compatible API, running on Nashorn. Project Avatar appears to be Oracle's answer to the NodeJS API, offering an alternative platform which also provides compatibility with the NodeJS API and ecosystem via Avatar.js.

Therefore it is not that Project Avatar is built on Avatar.js, but rather that "Avatar.js is one component of Project Avatar. Nashorn is the JavaScript engine used to run both." (again, from this post).

The Avatar.js homepage currently has a list of modules known to run, including "grunt". It would appear that Project Avatar currently includes a build of Avatar.js as "avatar-js.jar", as found in the current latest commit, though it is 4 months old. So I think the answer is that yes, the current build of Project Avatar will allow you to run Node-compatible modules.

As you've pointed out, both of these initiatives lack documentation, and are in their infancy. Time and community engagement will show where they fit best.

4
jbandi On

Indeed there is Avatar.js included in Project Avatar. By looking at the Maven POM files of Project Avatar, I discovered that there is a binary distribution of Avatar.js available through the java.net Maven repository.

Based on this discovery I wrote a blog post how to run simple Node.js apps with Avatar.js here: Running Node.js applications on the JVM with Nashorn and Java 8

Steps for OSX repeated here:

  1. Download avatar-js.jar from the java.net Maven Repo. Current version is here: https://maven.java.net/content/repositories/public/com/oracle/avatar-js/0.10.25-SNAPSHOT/ Example file: avatar-js-0.10.25-20140313.063039-43.jar
  2. Download the native library avatar-js.dylib from the java.net Maven Repo. Current version is here: https://maven.java.net/content/repositories/public/com/oracle/libavatar-js-macosx-x64/0.10.25-SNAPSHOT/
    Example file:libavatar-js-macosx-x64-0.10.25-20140312.062209-35.dylib
    For Linux you would download the corresponding .so file from ../libavatar-js-linux-x64/0.10.25-SNAPSHOT/
    For Windows you would download the corresponding .dll file from ../libavatar-js-win-x64/0.10.25-SNAPSHOT/
  3. Rename the native library to avatar-js.dylib and rename the jar to avatar-js.jar and put both in a directory called dist.
  4. Create a simple Node.js app in the a file called app.js.
  5. Run the command: java -Djava.library.path=dist -jar dist/avatar-js.jar app.js
1
Bryan On

Project Avatar does indeed layer on top of Avatar.js; the code is integrated into our build using Maven. (The jar you found, Johann, was old because we no longer use it -- I just nuked it, thanks).

And yes, we're aware that our docs need more work. For now, we are focussing on fleshing out the server-side JavaScript framework. This services layer provides a runtime tuned for easily creating REST, WebSocket and Server-Sent Event endpoints.