symjascript
A command-line interpreter for Symja, the Java
computer algebra system with a syntax close to Mathematica's. Its command line is modelled on
Wolfram's wolframscript:
the same options run code, scripts and functions, and a -wstp kernel mode lets the
WLJS Notebook drive Symja as its kernel.
It ships in two builds from the same source:
| build |
runtime |
start-up |
raster output (-format PNG, Image[]) |
| jar + launcher scripts |
any Java 11+ |
~1 s |
yes |
| GraalVM native binary |
none |
~0.3 s |
Linux, Windows; not macOS |
This README is for developers: how to build every variant, install it, and what each argument
does. The end-user READMEs that ship inside the zips are
src/dist/README.txt and
src/dist/native/README.txt.
Repository layout
README.md this file
matheclipse-console/ the Maven project (standalone, no <parent>)
pom.xml
src/main/java/org/matheclipse/console/
SymjaScript.java entry point: options, modes, REPL
SymjaCompleter.java TAB completion
SymjaHighlighter.java REPL syntax colouring
Rasterizer.java SVG -> PNG/JPEG/...; the only AWT code
src/main/resources/META-INF/native-image/org.matheclipse/matheclipse-console/
reachability-metadata.json JLine terminal providers for the native image
src/assembly/
distribution.xml the portable zip
native-distribution.xml the native zip
src/dist/
bin/symjascript(.bat), bin/symja(.bat) launchers (symja = alias)
README.txt, native/README.txt, LICENSE-*.txt
src/test/
java/.../SymjaScriptTest.java JUnit tests of the command line
pty/ terminal harnesses (ptyrun.py, ptytype.py)
wljs/ start scripts for manual WLJS Notebook tests
The Maven artifact is still called org.matheclipse:matheclipse-console; the program, the
launchers and the zips are called symjascript.
Prerequisites
| to build |
you need |
| jar, zip, launcher |
JDK 17 or newer and Maven 3.9 |
| native binary |
additionally GraalVM for JDK 21 or newer (developed on Oracle GraalVM 25) |
The Symja dependency
symjascript depends on three Symja modules at version ${symja.version} (3.3.0-SNAPSHOT):
matheclipse-core, matheclipse-image and matheclipse-graphtheory. The pom declares two
snapshot repositories to resolve them without a local Symja checkout:
central.sonatype.com/repository/maven-snapshots for the Symja snapshots
packages.orekit.org/repository/maven-snapshots for hipparchus 4.1-SNAPSHOT, which Symja
needs and which only lives there
The console often needs Symja changes that are not published yet. When that happens the
build fails to compile with "cannot find symbol" against a Symja class. Build the Symja modules
from source into your local repository first:
git clone https://github.com/axkr/symja_android_library.git
git clone https://github.com/axkr/symjascript.git
cd symja_android_library/symja_android_library
mvn -pl matheclipse-core,matheclipse-image,matheclipse-graphtheory -am install -DskipTests
-am also builds the modules those three need (parser, external, logging, gpl, script). Keep
the two clones side by side: the WLJS scripts expect symja_android_library next to this
repository.
Two traps when working against a local Symja:
Building
Run all builds from matheclipse-console/.
Jar, portable zip and development launcher
cd symjascript/matheclipse-console
mvn package
This compiles, runs the tests and produces:
file in target/ |
size |
what it is |
matheclipse-console-3.3.0-SNAPSHOT.jar |
35 KB |
the console classes only |
matheclipse-console-3.3.0-SNAPSHOT-all.jar |
48 MB |
uber jar: every dependency, java -jar runnable |
symjascript-3.3.0-SNAPSHOT.zip |
44 MB |
portable distribution (see Installing) |
appassembler/bin/symjascript (+ .bat) |
|
development launcher over appassembler/lib/*.jar |
- Add
-DskipTests to skip the tests, and -o to build offline once ~/.m2 is filled.
- The uber jar is built by
maven-shade-plugin, which also:
- drops the signature files of signed dependencies (otherwise the jar fails with "Invalid
signature file digest");
- merges the
META-INF/services files JLine uses to find its terminal backends;
- writes
Multi-Release: true and Enable-Native-Access: ALL-UNNAMED into the manifest. The
latter silences the Java 24+ restricted-method warnings for JLine's native library. It is a
manifest entry rather than a launcher flag because Java 11 ignores an unknown manifest
attribute but refuses to start on an unknown flag.
- The portable zip is
maven-assembly-plugin with src/assembly/distribution.xml. It renames
the uber jar to lib/symjascript.jar, so the launchers need not know the version.
appassembler-maven-plugin never deletes old files. If you see appassembler/bin/symja
launchers pointing at MMAConsole, or duplicate jar versions in appassembler/lib, run
mvn clean package.
Native binary
export JAVA_HOME=/path/to/graalvm # see Prerequisites
mvn -Pnative package -DskipTests # binary only
mvn -Pnative verify -DskipTests # binary and its zip
file in target/ |
size |
built by |
symjascript |
~170 MB |
-Pnative package |
symjascript-3.3.0-SNAPSHOT-<os>-<arch>.zip |
~66 MB |
-Pnative verify |
The native profile also builds everything from the jar build. A native build takes about
5 minutes.
- Use
verify for the zip. The base build already declares maven-assembly-plugin for the
portable zip, so an assembly execution added in the profile at package would run before
native-maven-plugin and try to zip a binary that does not exist yet. The native zip is bound
to verify instead.
- The zip name carries the platform from
os-maven-plugin (${os.detected.classifier}, e.g.
osx-aarch_64, linux-x86_64), which is the naming JReleaser expects.
- native-image does not cross-compile. The binary runs only on the OS and CPU it was built
on, so each platform needs its own build. For macOS on both CPUs, build twice and join the
results with
lipo -create.
native-maven-plugin is 1.x. The 0.10.x plugins look for GraalVM's removed gu tool and stop
with "not a GraalVM distribution".
- Build arguments:
--no-fallback, -J-Xmx${native.build.maxheap}, and
--enable-native-access=ALL-UNNAMED. The native counterpart of the manifest entry has to be
given at build time; passing it to the binary does nothing.
Native-image metadata
Reflection and resources that native-image cannot discover are declared in
reachability-metadata.json files, next to the code that needs them:
| module |
file |
registers |
| console |
src/main/resources/META-INF/native-image/org.matheclipse/matheclipse-console/ |
JLine and Jansi terminal providers, native libraries, capability files |
| matheclipse-core |
.../org.matheclipse/matheclipse-core/ |
rule classes loaded by name, apfloat builder factories, resources such as documentation, units and colour data |
| matheclipse-graphtheory |
.../org.matheclipse/matheclipse-graphtheory/ |
the edge constructors JGraphT creates reflectively |
Libraries covered by the GraalVM reachability metadata repository are handled automatically
(metadataRepository is enabled). When a function works in the jar but not in the native
binary, a missing entry is the usual cause: a ClassNotFoundException or a
NoSuchMethodException ... <init>() names what to add. Recording a session with the tracing agent
produces a starting point. Run it with GraalVM's java, which provides the agent:
java -agentlib:native-image-agent=config-output-dir=/tmp/ni-config \
-jar target/matheclipse-console-3.3.0-SNAPSHOT-all.jar
Installing
Portable distribution (any OS with Java 11+)
unzip target/symjascript-3.3.0-SNAPSHOT.zip -d ~/opt
ln -s ~/opt/symjascript-3.3.0-SNAPSHOT/bin/symjascript ~/bin/symjascript # or add bin/ to PATH
symjascript -version
symjascript-3.3.0-SNAPSHOT/
bin/symjascript bin/symjascript.bat launchers
bin/symja bin/symja.bat aliases for the old name
lib/symjascript.jar the uber jar
README.txt LICENSE-GPL.txt LICENSE-LGPL.txt
bin/ must stay next to lib/: the launcher finds the jar relative to itself and follows a
symlink back to the distribution.
- It uses
$JAVA_HOME/bin/java if JAVA_HOME is set, otherwise java from the PATH, and
passes JAVA_OPTS to the JVM: JAVA_OPTS=-Xmx4g symjascript.
- Without the launcher:
java -jar lib/symjascript.jar.
Native binary
unzip target/symjascript-3.3.0-SNAPSHOT-osx-aarch_64.zip -d /tmp
cp /tmp/symjascript-3.3.0-SNAPSHOT-osx-aarch_64/bin/symjascript /usr/local/bin/
- The binary depends on nothing next to it, so copying it alone is enough.
- On macOS the binary is not notarized. Clear the quarantine flag of a downloaded copy with
xattr -d com.apple.quarantine /usr/local/bin/symjascript.
During development
target/appassembler/bin/symjascript runs the classes and dependency jars straight out of
target/, with no zip in between. The WLJS start scripts use it. To make it your symjascript:
ln -s "$PWD/target/appassembler/bin/symjascript" ~/bin/symjascript
Usage
Modes
| command |
mode |
symjascript |
interactive session (JLine: history, TAB completion, highlighting) |
symjascript -code '<code>' |
evaluate once and print the result |
symjascript -f script.wls [args...] |
run a script; -file, -script and a bare file name work too |
./script.wls [args...] |
run a script through its #! line |
symjascript -function f -args 1 2 |
evaluate f[1, 2] |
symjascript < program.wls |
no work asked for and stdin is not a terminal: run stdin as a script |
symjascript -wstp |
kernel link: read packets on stdin, answer on stdout |