Environment:APIJSON APIJSON Demo Java 17
| Knowledge Sources | |
|---|---|
| Domains | Runtime, Scripting, Infrastructure |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
JDK 17+ runtime with standalone Nashorn 15.4 and LuaJ script engines, required for server-side script execution and dataset generation in the APIJSON Demo.
Description
This environment provides the Java 17+ runtime needed for script executors that require engines not bundled with the JDK. Since JDK 15, Nashorn was removed from the JDK and must be included as a standalone dependency (org.openjdk.nashorn:nashorn-core). LuaJ provides Lua script execution via the JSR 223 scripting framework. Both engines require JDK 17 or higher as the base runtime.
Usage
Use this environment for script executor implementations: NashornScriptExecutor and LuaScriptExecutor, as well as DatasetUtil which requires JDK 17+ for its image processing and COCO dataset generation utilities.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux / macOS / Windows | Any OS supporting JDK 17 |
| Hardware | 1GB RAM minimum | Script execution is CPU-bound |
| Disk | 500MB | For JDK installation and script libraries |
Dependencies
System Packages
- JDK 17 or higher
Java Packages
- `nashorn-core` = 15.4 (org.openjdk.nashorn) — standalone Nashorn for JDK 17+
- `luaj` (via JSR 223) — Lua script engine
- `APIJSON` = 7.1.0 (Script module)
- `apijson-framework` = 7.1.5 (Script module)
Credentials
No environment variables required.
Quick Install
# Install JDK 17 (Ubuntu/Debian)
sudo apt install openjdk-17-jdk
java -version # Verify: openjdk version "17.x.x"
# Maven dependencies (in APIJSONDemo-Script/pom.xml)
# nashorn-core 15.4 and graalvm js 21.3.3.1 are declared
Code Evidence
Nashorn standalone import comment from `NashornScriptExecutor.java:11-12`:
// JDK 1.8~16 用 JDK 自带的,JDK 17+ 必须单独依赖
import org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory;
LuaJ engine name from `LuaScriptExecutor.java:14-16`:
@Override
protected String scriptEngineName() {
return "luaj";
}
JDK 17 build target from `APIJSONDemo-Script/pom.xml:16-17`:
<java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source>
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `ClassNotFoundException: jdk.nashorn.api.scripting.NashornScriptEngineFactory` | Nashorn removed from JDK 15+ without standalone dependency | Add `org.openjdk.nashorn:nashorn-core:15.4` to pom.xml |
| `ScriptEngine not found: luaj` | LuaJ not on classpath | Ensure APIJSON framework includes LuaJ or add manually |
| `Unsupported class file major version` | JDK version mismatch between build and runtime | Ensure both build and runtime use JDK 17+ |
Compatibility Notes
- JDK 8-16: Nashorn is bundled with the JDK — no standalone dependency needed.
- JDK 17+: Nashorn must be added as `org.openjdk.nashorn:nashorn-core` dependency.
- LuaJ thread safety: LuaJ is not thread-safe for concurrent execution of the same script. Use per-script synchronized locking (see Heuristic:APIJSON_APIJSON_Demo_Per_Script_Synchronized_Locking).