Menu

Embedding Aussom: Choosing an Approach

Aussom is designed to be embedded inside larger Java applications. There are two supported ways to do that, and the right one depends on how much control you need over the runtime.

This page is a one-screen overview to help you pick. Once you've chosen, follow the linked deep-dive guide for the full how-to.


The two approaches

1. JSR 223 (javax.script)

Aussom ships with a JSR 223 ScriptEngine implementation. You go through the standard Java scripting interfaces: ScriptEngineManager, ScriptEngine, Bindings, Compilable, Invocable. The engine is auto-discovered from the classpath; no configuration code is needed.

Use this when:

  • You're scripting a host that already speaks JSR 223 (or might someday support multiple scripting languages).
  • You want a small, language-neutral surface area: eval, put, get, compile, invokeFunction.
  • Bindings, type marshalling, and stdout/stderr routing through ScriptContext writers cover what you need.
  • You don't need custom security policy at the Java level (the default is reasonable; tighter policies require subclassing the factory).

Read the full guide: Embedding Aussom via JSR 223


2. Direct Engine API (standard embedding)

The lower-level path. You construct com.aussom.Engine yourself, hand it a SecurityManagerInt, parse sources, and either call run() or dispatch into Aussom code by name. This is what the JSR 223 layer is built on top of, and what the Aussom CLI uses.

Use this when:

  • You need to customize the security policy -- subclass SecurityManagerImpl, gate operations behind your own property names, flip permissions on or off at runtime.
  • You're wrapping Java classes as Aussom extern classes so scripts can call into your host's APIs (the same pattern the stdlib uses for c, sys, math, etc.).
  • You need fine-grained control over the parse / run lifecycle: multiple includes, custom search paths, doc-mode parsing, reflection.
  • You're building a non-standard runner (a CLI, a browser-side interpreter, an IDE plugin) on top of aussom-base.

Read the full guide: Embedding Aussom Directly


Side by side

Concern JSR 223 Direct Engine API
Setup Auto-discovered via SPI new Engine(SecurityManagerInt)
Run a snippet engine.eval("...") parseString(...) + run()
Pass values in engine.put(k, v) -> this.bindings["k"] Bindings on the synthetic class, or args
Get values out Return from eval AussomType returned from method calls
Pre-compile Compilable.compile(...) parseString once, instantiate / call later
Call by name Invocable.invokeFunction(...) astClass.call(env, false, name, args)
Custom security policy Subclass the factory First-class -- always pick a SecurityManagerInt
Wrap Java classes for scripts Limited (opaque object passthrough) Full -- the stdlib pattern
Control over parse lifecycle Hidden behind eval / compile Full control: multiple parses, includes, etc.
Output routing Per-call ScriptContext writer Per-thread console.get().register(LoggingInt)
Threading model MULTITHREADED advertised; engine handles serialization You manage Environment / CallStack per call
Migration cost Small -- standard interfaces Larger -- bespoke API

Quick decision tree

  • "I just want to run user scripts and pass a few values." -> JSR 223.

  • "I want to expose my host's services to scripts." -> Direct Engine API. You'll be writing extern classes.

  • "I need a lockdown sandbox for untrusted code." -> Direct Engine API. Build a custom SecurityManagerInt.

  • "My host already runs JavaScript / Groovy via JSR 223 and I want Aussom too." -> JSR 223. Drop the Aussom jar on the classpath; nothing else changes in your scripting framework.

  • "I'm building the next Aussom-aware tool (CLI, IDE plugin, REPL, browser runtime)." -> Direct Engine API. Look at Main.java and the aussom-script / aussom repos as references.

You can also use both. The JSR 223 layer is layered on top of the same Engine class, and a host that mostly uses JSR 223 can still reach the underlying engine via ((AussomScriptEngine) engine) .getAussomEngine() for the rare advanced case.


See also