JavaアプリケーションにGoogleJavaScriptエンジンV8を埋め込むためのソリューションを探しています。
あなたはいくつかの解決策を持っていますか?
JavaアプリケーションにGoogleJavaScriptエンジンV8を埋め込むためのソリューションを探しています。
あなたはいくつかの解決策を持っていますか?
J2V8https://github.com/eclipsesource/J2V8を使用できます。MavenCentralでも利用できます。
以下はHello、World!です。J2V8を使用したプログラム。
package com.example;
import com.eclipsesource.v8.V8;
public class EclipseCon_snippet5 {
public static class Printer {
public void print(String string) {
System.out.println(string);
}
}
public static void main(String[] args) {
V8 v8 = V8.createV8Runtime();
v8.registerJavaMethod(new Printer(), "print", "print", new Class<?>[]{String.class});
v8.executeVoidScript( "print('Hello, World!');" );
v8.release(true);
}
}
pom.xmlでプラットフォームを指定する必要があります。J2V8は現在、win32_x86、macosx_x86_64、android_x86、およびandroid_armv7lをサポートしています。それらが異なる理由は、ネイティブバインディングとバンドルされているV8のビルド済みバージョンのためです。
たとえば、MacOSでは使用できます。
<dependencies>
<dependency>
<groupId>com.eclipsesource.j2v8</groupId>
<artifactId>j2v8_macosx_x86_64</artifactId>
<version>2.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
たぶん、GoogleV8JavascriptエンジンにJavaScriptingAPI(JSR223)ベースを実装するJav8を試すことができます。私は数週間前から取り組んでおり、ほとんどの単純なシーンをサポートできます。