In jjs (the old Java Nashorn shell), there isn’t a built-in “auto run as you type” mode like some modern editors. What you can do is run a script automatically when the shell starts, or use a loop/launcher script to rerun your file after edits.

What auto-run usually means

People use “auto run” in a few different ways:

  • Run a script immediately when jjs opens.
  • Re-run a file every time you save it.
  • Keep a script alive and repeat it on a timer or file-change trigger.

For jjs, the first case is the native one; the others usually require an external watcher or wrapper script.

Start a script automatically

If you want jjs to execute a file right away, launch it with the script name:

bash

jjs myscript.js

You can also pass code directly on the command line for quick tests. The shell is designed to invoke Nashorn scripts from the command line.

Re-run on changes

jjs itself does not provide a built-in file-watch auto-refresh loop. To get that behavior, use an external file watcher such as a shell loop, fswatch, entr, or a similar tool that re-invokes jjs whenever your file changes. That is the typical workaround for auto-run workflows around jjs.

Simple example

A basic pattern looks like this:

bash

while inotifywait -e close_write myscript.js; do
  jjs myscript.js
done

On macOS or Windows, use the equivalent watcher for that platform. The idea is the same: the watcher detects saves, then relaunches the script.

Practical note

If you meant RunJS instead of jjs, its Auto Run setting is built in and enabled by default. You can turn it off in Settings → General if needed.

TL;DR: `jjs` does not have a native live auto-run mode; use `jjs myscript.js` for startup execution, or pair it with a file watcher to rerun on save.[8]