Announcing J2V8 4

After over a year of development, I am very excited to announce that J2V8 4 is publicly available on all supported platforms. J2V8 is a set of V8 bindings for Java. This means that you can embed V8 (Google’s ultra fast JavaScript engine) into your Java applications. J2V8 4 is built on Node.js, which means you can also integrate Node.js with the JVM (On Windows, Mac and Linux).

J2V8-with-no-2-and-J

The biggest change in J2V8 4 is the use of V8 4.x, which enables many ES6 features.

public static void main(String[] args) {
  V8 v8 = V8.createV8Runtime();
  int x = (Integer) v8.executeScript("var func = x => x * x; func(5);");
  System.out.println(x);
  v8.release();
}

A number of notable features have been included in J2v8 4. I will expand on each of these further:

  1. Running Node.js on the JVM
  2. ByteBuffer backed TypedArrays (Shared memory between Java and V8)
  3. UTF-16 Support
  4. JavaScript functions written entirely in Java
  5. Improved Memory Management API

In addition to these New and Noteworthy features, a number of new APIs have been added. It’s easier to call JavaScript functions from Java, the memory model for callbacks has been improved, and build instructions have been published.

The technical version is 4.5.0 because we had a number of pre-releases for single platforms. This is the first time that all this work has been released for all supported platforms. J2V8 currently supports: Windows 32, Windows 64, MacOS, Linux 64, Android ARM and Android x86 (The Node.js integration is not available in the Android builds).

You can use J2V8 4 today by adding the following dependency to your pom.xml file.

com.eclipsesource.j2v8
  j2v8_macosx_x86_64
  4.5.0

The artifacts are system dependent because they include native libraries. Replace the artifactId for other platforms:

  • j2v8_macosx_x86_64
  • j2v8_win32_x86_64
  • j2v8_win32_x86
  • j2v8_linux_x86_64

Or use the following pom dependency to consume an Android AAR archive for Arm and x86:

com.eclipsesource.j2v8
  j2v8
  4.5.0
  aar

For more news on J2V8, follow me on Twitter.

 

6 Comments
  • Bernat
    Posted at 7:21 pm, July 27, 2016

    Hi!

    In my Java code can I access and execute JavaScript functions of a separate .js file? If so, can you please describe me how?

    Thank you:

    Bernat

  • Min Idzelis
    Posted at 9:44 pm, July 27, 2016

    Can you explain how debugging works? Do I have to use Google’s eclipse plugin to debug node, or can I open http://127.0.0.1:8080?port=5858 to show the embedded node.js chrome dev tools, which is how I typically debug node.js apps?

  • Bernat
    Posted at 12:38 pm, August 9, 2016

    @Ian Bull, I asked it on StackOverflow. The link is: http://stackoverflow.com/questions/38848274/execute-function-from-js-with-j2v8

  • AtulV
    Posted at 5:28 pm, February 19, 2017

    Where can I download the latest jar files for J2v8?

    • Gosia Mitros
      Posted at 1:23 pm, February 27, 2017

      J2v8 is available from Maven Central. The latest release is 4.6.0.