Home > Java, SimpleScript > SimpleScript – Installation

SimpleScript – Installation

SimpleScript allows you to use Java language as a script language. It is done this by compiling the script transparently. Well, almost. The fact is SimpleScript does not actually compile the script, instead it ask JavaC to do it. Also, it does not actually execute the script but asks JVM (that SimpleScript is running) to run it. This has important implication that a script written for SimpleScript is compiled as a Java code and executed as a Java byte-code. In other words, a simple script is literally Java. And because of that, you can do a lot of things with it.

Now, if you are interested in SimpleScript and want to try it, this post will explain how.

1. Install JDK 6.0 or higher
Repeat the JDK. This because you needs tools.jar which contains javac and related classes. Unfortunately, tools.jar is not allowed to be re-distributed. So, again, you need to install Java SDK 6.0. You can get the JDK here or install “sun-java6-jdk” package if you are on Ubuntu. Install it any where you like just remember where (on Ubuntu, it should be at ‘/usr/lib/jvm/java-6-sun-1.6.0.xx/’).

2. Download SimpleScript
Just download it from: http://blog.nawaman.net/simplescript/simplescript-downloads/.

Then, put it anywhere you like and remember it. You many add it in your default classpath if you plan to use it a lot. In Linux, you may put it in a share folder like ‘/usr/lib/SimpleScript/’ if you want other users to see.

Now, you can try to run it, like this (Linux):

java -classpath /path/to/sdk:/path/to/:/path/to/tools.jar:/path/to/SimpleScript -jar SimpleScript-bin.jar  --command "/* @Java: */ return 5 + 10;"

or this (for Windows):

java -classpath /path/to/sdk;/path/to/;/path/to/tools.jar;/path/to/SimpleScript -jar SimpleScript-bin.jar  --command "/* @Java: */ return 5 + 10;"

The program should return “15″;

3. Create an execution file – Linux only
This step will make your life easier. Simply create the following script in your PATH.

<PATH>/ss

#!/bin/bash
SCRIPTPATH=/path/to/test/dot/ss/
TOOLSPATH=/path/to/jdk6-or-up/tools.jar
java -classpath $TOOLSPATH:$SCRIPTPATH -jar SimpleScript-bin.jar --run "$@"

Now, you can run:

ss --command "/* @Java: */ return 5 + 10;"

This should return 15.

4. Set environmental variablesUPDATED!!!

JAVA_HOME to the home folder of your Java SDK.

PATH to include JAVA_HOME.

DONE!!!

To confirm everything is alright, let create a script:
test.ss

// @Java: { main }
System.out.println("Hello World!!!");

Run it:

ss --run test.ss

“Hello World!!!” should be printed out.

If you are on Linux, you can try to use shebang like this:
test.ss

#!/path/to/ss --run
// @Java: { main }
System.out.println("Hello World!!!");

Make test.ss an executable and run it:

./test.ss

You should get “Hello World!!!” as the previous run.

Let enough for now, enjoy coding.
NawaMan


Copyright 2010: Nawapunth Manusitthipol
Categories: Java, SimpleScript Tags: