
Manual
Next chapter: Executing Documents
Or, go back to the manual's table of contents
Part 1: Bootstrapping Applications
Scripturian comes with a ready-to-rumble execution environment that lets you execute file-based documents immediately, without writing any Java code. (The rest of the tutorial will show you how to execute documents programmatically from Java.)
First, create your entry point code. For this example, we'll use JavaScript, and create a file named "start.js":
print('Hello, world, from Scripturian!');
To run this code, make sure the Scripturian jar, and required language engine jars, are on your JVM classpath. Then, from the command line run:
java com.threecrickets.scripturian.Scripturian /start/
Ta da! You've just used JavaScript on the JVM without writing a single line of Java code. Moreover, you can easily swap the language implementation: make a "start.rb" file instead of a "start.js" file to use Ruby instead of JavaScript.
Your entire application can then proceed from that initial entry point without ever requiring Java.
API Services
Scripturian exposes a few API services to your executables: executable, document, and application. Click the links to see the API documentation for each. An example of usage:
application.globals.put('name', 'world'); print('Hello, ' + application.globals.get('name') + ', from Scripturian!'); document.execute('/server/');
Command Line Arguments
The defaults may be good enough, but you can also configure your bootstrapping:
- If you do not specify the document name, Scripturian will try to run the document specified by --default-document-name (see below)
- --base-path=.: Use this to change the base path in which documents will be looked for, the default is the current directory.
- --preferred-extension=js: When filename extensions aren't specified, this extension will be preferred.
- --prepare=true: The default it true, but you can set "prepare" to false to force Scripturian not to compile your source code. Not all languages support this, but if they do, this will cause them to run in "interpreted" mode, which may be slower, but may have faster startup time.
- --default-document-name=default: If a document name points to a directory instead of a file, then Scripturian will look in that directory for a file with this name.
- --document-service-name=document and --application-service-name=application: Use these to change the names of these two API services (useful in case there is conflict with other APIs).
Special Note for Jython
To use Jython, you must specify the "python.home" JVM property. Jython will look for its "Lib" directory underneath the home directory:
java -Dpython.home=~/jython/ com.threecrickets.scripturian.Scripturian /start/
Changing the Cache Location
By default, Scripturian will cache prepared (compiled) documents under "scripturian/cache" relative to the current directory, but you can set this explicitly via the "scripturian.cache" JVM property:
java -Dscripturian.cache=/tmp/scripturian/ com.threecrickets.scripturian.Scripturian /start/
Note that you may delete these cached file at any time, and Scripturian will regenerate them if necessary.
Next chapter: Executing Documents
Or, go back to the manual's table of contents