Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:APIJSON APIJSON Demo GraalVM

From Leeroopedia
Knowledge Sources
Domains Polyglot, Scripting, Runtime
Last Updated 2026-10-14 00:00 GMT

Overview

GraalVM polyglot SDK 21.3.3.1 with JS engine, enabling server-side JavaScript execution via the GraalVM Context API for the APIJSON Demo's custom function system.

Description

This environment provides the GraalVM polyglot runtime for executing JavaScript functions server-side. The GraalJavaScriptExecutor uses org.graalvm.polyglot.Engine and Context to evaluate JS scripts. Scripts are compiled as Source objects and cached in a ConcurrentHashMap for thread-safe lookups. Each execution creates a fresh Context with allowAllAccess(true), preventing cross-request contamination. The environment requires the org.graalvm.js:js artifact on the classpath.

Usage

Use this environment for the GraalJavaScriptExecutor implementation, which executes custom JavaScript functions registered via the APIJSON function parser. This is an alternative to the Nashorn-based executor and provides better performance and modern JS (ES2020+) support.

System Requirements

Category Requirement Notes
OS Linux / macOS / Windows Any OS supporting JDK 17
Hardware 1GB RAM minimum GraalVM contexts are memory-intensive
Disk 500MB For GraalVM JS engine JARs

Dependencies

System Packages

  • JDK 17 or higher

Java Packages

  • `org.graalvm.js:js` = 21.3.3.1
  • `org.graalvm.js:js-scriptengine` = 21.3.3.1 (optional, for JSR 223 integration)
  • `org.openjdk.nashorn:nashorn-core` = 15.4 (co-resident in Script module)

Credentials

No environment variables required.

Quick Install

# GraalVM JS engine is a Maven dependency, no separate installation needed.
# Ensure APIJSONDemo-Script/pom.xml includes:
# <dependency>
#     <groupId>org.graalvm.js</groupId>
#     <artifactId>js</artifactId>
#     <version>21.3.3.1</version>
# </dependency>

Code Evidence

GraalVM polyglot imports from `GraalJavaScriptExecutor.java:3-7`:

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;

Engine and context creation from `GraalJavaScriptExecutor.java:24-27,44`:

@Override
public ScriptExecutor init() {
    engine = Engine.create();
    return this;
}

// Per-call context with full access:
Context context = Context.newBuilder().allowAllAccess(true).engine(this.engine).build();

GraalVM dependency from `APIJSONDemo-Script/pom.xml:68-72`:

<dependency>
    <groupId>org.graalvm.js</groupId>
    <artifactId>js</artifactId>
    <version>21.3.3.1</version>
</dependency>

Common Errors

Error Message Cause Solution
`java.lang.NoClassDefFoundError: org/graalvm/polyglot/Engine` GraalVM JS not on classpath Add `org.graalvm.js:js:21.3.3.1` dependency
`PolyglotException: SyntaxError` Invalid JavaScript in registered script Validate JS syntax before calling `load()`
`Context creation failed` Insufficient memory or JDK version too low Ensure JDK 17+ and sufficient heap space

Compatibility Notes

  • Not native GraalVM required: The GraalVM JS engine runs on any JDK 17+ — the full GraalVM distribution is not required, just the `js` artifact.
  • allowAllAccess(true): The context grants full host access, which is needed for scripting but has security implications in production.
  • Per-call context: Each execute() creates a new Context, ensuring isolation but incurring creation overhead. The Engine is shared and cached.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment