From ad683cc622c127a6a5cd73931802a539ca09a22e Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Mon, 23 Sep 2024 22:46:42 -0700 Subject: [PATCH] Add simple Main program that executes a hard-coded JS file --- .../endoflineblog/truffle/part_15/Main.java | 23 +++++++++++++++++++ part-16/src/main/resources/example.js | 1 + 2 files changed, 24 insertions(+) create mode 100644 part-16/src/main/java/com/endoflineblog/truffle/part_15/Main.java create mode 100644 part-16/src/main/resources/example.js diff --git a/part-16/src/main/java/com/endoflineblog/truffle/part_15/Main.java b/part-16/src/main/java/com/endoflineblog/truffle/part_15/Main.java new file mode 100644 index 00000000..a2e5d935 --- /dev/null +++ b/part-16/src/main/java/com/endoflineblog/truffle/part_15/Main.java @@ -0,0 +1,23 @@ +package com.endoflineblog.truffle.part_15; + +import org.graalvm.polyglot.Context; +import org.graalvm.polyglot.Source; +import org.graalvm.polyglot.Value; + +import java.io.File; +import java.io.IOException; + +public class Main { + public static void main(String[] args) throws IOException { + Source source = Source + .newBuilder("ezs", new File("src/main/resources/example.js")) + .build(); + + try (Context context = Context + .newBuilder() + .build()) { + Value result = context.eval(source); + System.out.println(result.toString()); + } + } +} diff --git a/part-16/src/main/resources/example.js b/part-16/src/main/resources/example.js new file mode 100644 index 00000000..a31eda83 --- /dev/null +++ b/part-16/src/main/resources/example.js @@ -0,0 +1 @@ +"example.js";