Javet is Java + V8 (JAVa + V + EighT). It is an awesome way of embedding Node.js and V8 in Java.
In Oct, 2020, I was looking for a solution about running JavaScript code in JVM with identical behavior as in a web browser. V8 seemed to be only candidate and the available solution was J2V8.
However, J2V8 has dropped support for Linux in 2017 and Windows in 2016. The V8 doesn’t even completely support ES6.
In Jan, 2021, I started an open-source project https://github.com/caoccao/Javet/ from scratch. Now, it is fully functional and reaches production level.
Major Features
- 🐧Linux + 🖥️Windows
- Node.js
v14.16.1
+ V8v9.0.257
- Dynamic switch between Node.js and V8
- Exposure of the majority of V8 API in JVM
- JS function interception
- Native BigInt and Date
- Javet engine pool
- Easy spring integration
- Live debug with Chrome DevTools
Quick Start
Dependency
Maven
<dependency>
<groupId>com.caoccao.javet</groupId>
<artifactId>javet</artifactId>
<version>0.8.7</version>
</dependency>
Gradle Kotlin DSL
implementation("com.caoccao.javet:javet:0.8.7")
Gradle Groovy DSL
implementation 'com.caoccao.javet:javet:0.8.7'
Hello Javet
// Node.js Mode
try (V8Runtime v8Runtime = V8Host.getNodeInstance().createV8Runtime()) {
System.out.println(v8Runtime.getExecutor("'Hello Javet'").executeString());
}// V8 Mode
try (V8Runtime v8Runtime = V8Host.getV8Instance().createV8Runtime()) {
System.out.println(v8Runtime.getExecutor("'Hello Javet'").executeString());
}
No comments:
Post a Comment