java 中使用v8引擎_如何将V8嵌入Java应用程序?

您可以使用J2V8

https://github.com/eclipsesource/J2V8.它甚至可在

Maven Central。

下面是一个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上,您可以使用。

com.eclipsesource.j2v8

j2v8_macosx_x86_64

2.0

compile

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值