Interface ServerJSCLI


public interface ServerJSCLI

Server-Side JavaScript CLI

Smart GWT's server-side JavaScript modules can be executed from the command line for standalone processing, batch operations, or embedding in custom applications. This is separate from Server Scripting which runs within the servlet container.

Execution Modes

Two command-line execution modes are available:

Mode Runtime Use Case Java Integration
Node.js Node.js (v18+) CLI tools, build scripts, standalone processing None (pure JavaScript)
GraalJS Polyglot GraalJS via Polyglot Context API Custom Java applications embedding Smart GWT JS Full (runs inside JVM)

Server Module Files

Server-side execution uses specially prepared module files that exclude browser-dependent code. These modules are located in isomorphic/system/modules/:

  • ISC_Core_Server.js - Core framework (language extensions, data structures, communications)
  • ISC_DataBinding_Server.js - DataSource, RPCManager, and data binding logic
  • ISC_AI_Server.js - AI module including AI integration classes

Runtime Detection

Code can detect which runtime is active using Browser flags:

GraalJS Integration

For Java applications embedding Smart GWT JavaScript, two approaches are available:

  • Polyglot Context API - Provides finest control over the JavaScript execution environment. See GraalPolyglotDMI for detailed examples, required JARs, and setup instructions.
  • JSR-223 ScriptEngine - Standard Java Scripting API; simpler but less flexible. See ServerScript for configuration details.

JSEngineManager

Smart GWT provides JSEngineManager for automatic engine detection. It detects available engines and selects the best option:

  EngineInfo info = JSEngineManager.detectEngines(getClass().getClassLoader());
  ScriptEngine engine = JSEngineManager.createEngine(getClass().getClassLoader());
  

Engine Selection Priority:

  1. GraalJS Polyglot mode (preferred - best Java interop and performance)
  2. GraalJS via JSR-223 ScriptEngine
  3. V8 via J2V8 (if available with platform-specific native libraries)
  4. Nashorn (OpenJDK standalone JAR for Java 15+, or Oracle built-in for Java 8-14)

Nashorn Compatibility

Scripts written for Oracle Nashorn can run on GraalJS with Nashorn compatibility shims. Smart GWT automatically provides shims for common Nashorn constructs:

  • java.lang.*, java.util.* - Package shortcuts
  • Java.type() - Class loading (native to GraalJS)
  • importClass(), importPackage() - Legacy import functions

See GraalPolyglotDMI for using the Polyglot API from DMI within a servlet container, and ServerScript for using the JSR-223 ScriptEngine API for declarative scripts in .ds.xml files.