dependencies implementation 'io.github.java-addon:v8-repack:2025.01.22'
V8Object javaConsole = new V8Object(runtime); javaConsole.registerJavaMethod((receiver, parameters) -> System.out.println("JS Log: " + parameters.getString(0)); return null; , "log"); runtime.add("console", javaConsole); runtime.executeVoidScript("console.log('Hello from V8 repack!');"); javaConsole.release(); The number one source of crashes in raw J2V8 is memory leaks. A good repack adds automatic disposal via try-with-resources (as shown above). Always wrap your isolates. Part 6: Performance Benchmark – Repack vs. Legacy We ran a benchmark on an Intel i7-12700H, 32GB RAM, running Ubuntu 22.04. java addon v8 repack
import com.eclipsesource.v8.V8; import com.eclipsesource.v8.V8Array; import com.eclipsesource.v8.V8Object; public class V8RepackDemo public static void main(String[] args) try (V8 runtime = V8.createV8Runtime("secure_isolate")) // Execute simple JS int result = runtime.executeIntegerScript("(function() return 5 * 8; )();"); System.out.println("5*8 = " + result); dependencies implementation 'io
One major advantage of a well-repacked addon is reduced JNI overhead: Part 6: Performance Benchmark – Repack vs