Announcing J2V8 2.0

February 25, 2015 | 2 min Read

Last year I announced J2V8, a new JavaScript engine for Java that wraps V8 with a set of Java Bindings. We have been using this technology to power Tabris.js on Android – giving us much better performance than Rhino could. While J2V8 was very stable, it wasn’t very easy to consume. Today I’m happy to announce that J2V8 2.0 has shipped, and it’s much easier to embed in your Java Applications.

There are several notable improvements in J2V8 2.0:

Self Loading Native Libraries

Following the lead of SWT from years ago, we have included a Library Loader that will load the native library automatically for you. You no longer need to twiddle with the java.library.path to get J2V8 to work. This also works on Android.

Bundled Native Libraries

The native libraries have also been bundled with the Jar file. Currently we are shipping 5 different Jar files for J2V8:

The final one (j2v8_android.jar) contains the native library for both armv7l and x86, so you can use it on several different Android devices. By adding the jar to your classpath and calling V8 runtime = V8.createV8Runtime(); (V8.createV8Runtime(null, activity.getApplicationInfo().dataDir); on Android: because you need to specify the location to unpack the native library) the native library will be automatically loaded for you. We can add more platforms, but each one takes time as I need to build V8 on the platform first. Any particular platform I should target next?

Available in Maven Central

J2V8 is now available in Maven Central. You no longer need to build the library yourself. For example, add the following snippet to your pom.xml to use J2V8 on MacOS:


  com.eclipsesource.j2v8
  j2v8_macosx_x86_64
  2.0

Hello, World

Once you’ve added the the dependency to your pom.xml, you can begin embedding JavaScript in your Java Application using J2V8. Here is a simple Hello, World! that demonstrates how to call JavaScript from Java and register a callback.

package com.example;
import com.eclipsesource.v8.V8;
public class Hello {
 public void print(String s) {
  System.out.println(s);
 }
 public void start() {
  V8 v8 = V8.createV8Runtime();
  v8.registerJavaMethod(this, "print", "print", 
                                      new Class[] { String.class });
  v8.executeVoidScript("print('Hello, World!');");
 }
 public static void main(String[] args) {
  new Hello().start();
 }
}

More Information

I will presenting J2V8 at EclipseCon in San Fransisco on Thursday March 12th. Stop by and say hi if you’re in the area.

Finally, if you want to try it on Android without embedding it into your own Java application, request an invite to Tabris.js.

Ian Bull

Ian Bull

Ian is an Eclipse committer and EclipseSource Distinguished Engineer with a passion for developer productivity.

He leads the J2V8 project and has served on several …