←Older revision |
Revision as of 14:51, 15 July 2020 |
Line 1: |
Line 1: |
- | [https://avatar-js.java.net/ AvatarJS] is a re-implementation of [[NodeJS]] on top of the [[JVM]]. [[JDK]]8 comes with [[Nashorn]] and that is certainly better [[JavaScript]] virtual machine than old [[Rhino]]. However [[NodeJS]] is not just [[JavaScript]], it also contains a lot of native bindings. What can be done with those? | + | [https://avatar-js.java.net/ AvatarJS] was an attempt to re-implement [[NodeJS]] on top of the [[JVM]]. These days just download [[GraalVM]] and you'll get [[JavaScript]] and [[Java]] for free. Compatibility is guaranteed. |
- | | + | |
- | | + | |
- | === Get [[AvatarJS]] ===
| + | |
- | | + | |
- | Well, just download [[AvatarJS]] binaries and you are set to go. One could get the [[AvatarJS]] libraries from maven.java.net (as of Feb 17, 2014):
| + | |
- | | + | |
- | * The JAR: https://maven.java.net/index.html#nexus-search;quick~avatar-js
| + | |
- | * The native library: https://maven.java.net/index.html#nexus-search;quick~libavatar-js
| + | |
- | | + | |
- | To bind them together I renamed the libraries:
| + | |
- | | + | |
- | <source lang="bash">
| + | |
- | avatar-js.jar
| + | |
- | libavatar-js-linux-x64.so
| + | |
- | libavatar-js.so -> libavatar-js-linux-x64.so
| + | |
- | | + | |
- | # and then I could execute them as
| + | |
- | java -Djava.library.path=. -jar avatar-js.jar
| + | |
- | </source>
| + | |
- | | + | |
- | === Compatibility ===
| + | |
- | | + | |
- | Compatibility was tested on http://www.manning-source.com/books/cantelon/code_Node.js.zip sources. As of Mar 18, 2014 the 2/chat/ example works.
| + | |
- | | + | |
- | The 8 example is using '''const''' keyword in mongodb NodeJS modules (reported and fixed as https://bugs.openjdk.java.net/browse/JDK-8027933 on May 2nd, 2014). One can either replace the '''const''' with '''var''' or get latest [[Nashorn]] build.
| + | |
- | | + | |
- | Then the application starts, but crashes. The single line fix is documented on the [https://avatar-js.java.net/ AvatarJS] main page: inserting "if (options.locals)" was enough to fix the problem. Then the application started.
| + | |
| | | |
| === Tooling === | | === Tooling === |
| | | |
- | The [[NetBeans]] tooling (including excellent debugging, see [[Nashorn]]) is being developed at http://hg.netbeans.org/core-main/file/32b5ebff07b4/avatar_js.project | + | The [[NetBeans]] tooling (including excellent debugging, see [[Nashorn]]). |
- | | + | |
- | I know that [[Tim Boudreau]] has module with good [[NodeJS]] support as well and I let him put here a link once he also supports [[AvatarJS]].
| + | |
| | | |
| === Speed === | | === Speed === |
| | | |
| Yeah, so far [[V8]] is faster than [[Nashorn]], but let me point you to [http://www.slideshare.net/ThomasWuerthinger/2014-0424-graal-modularity presentation about next generation Nashorn] virtual machine to see where the speed will come from... | | Yeah, so far [[V8]] is faster than [[Nashorn]], but let me point you to [http://www.slideshare.net/ThomasWuerthinger/2014-0424-graal-modularity presentation about next generation Nashorn] virtual machine to see where the speed will come from... |