com.eclipsesource.node.J2V8Example Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of j2v8_win32_x86_64 Show documentation
Show all versions of j2v8_win32_x86_64 Show documentation
J2V8 is a set of Java bindings for V8
package com.eclipsesource.node;
import java.io.File;
import com.eclipsesource.v8.NodeJS;
import com.eclipsesource.v8.V8;
public class J2V8Example {
public String someJavaMethod(final String firstName, final String lastName) {
return firstName + ", " + lastName;
}
public void start() {
V8 v8 = V8.createV8Runtime();
System.out.println(V8.getV8Version());
v8.registerJavaMethod(this,
"someJavaMethod",
"someJavaMethod",
new Class[] { String.class, String.class });
v8.executeScript("var result = someJavaMethod('Ian', 'Bull');");
String result = v8.getString("result");
System.out.println(result);
}
public static void main(final String[] args) {
NodeJS nodeJS = NodeJS.createNodeJS();
nodeJS.exec(new File("node_example/myexpress.js"));
System.out.println("there");
while (nodeJS.isRunning()) {
nodeJS.handleMessage();
}
}
}