All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.eclipsesource.node.J2V8Example Maven / Gradle / Ivy

There is a newer version: 4.6.0
Show newest version
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();
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy