In Linux and Unix, a shebang is the character sequence consisting of the characters "number sign" and "exclamation mark" (that is, "#!").
When it occurs as the initial two characters on the first line of a shell script, the rest of the script is executed by the interpreter specified on that line. For example, if the first line of a script begins with "#!/bin/bash" then the script is executed by "bash".
Because the command interpreter is known as a "shell" and because the "exclamation mark" suggests excitement (as in "bang"), the two characters and the rest of the first line is called the "shebang".
There are two ways to use patrodyne-scripting-java-X.X.X.jar:
The JAR for this project can be executed directly:
Linux: java -jar patrodyne-scripting-javabang-X.X.X.jar $* Windows: java -jar patrodyne-scripting-javabang-X.X.X.jar %* Example: java -jar patrodyne-scripting-javabang-X.X.X.jar HelloWorld.java arg0 arg1 arg2
In the above examples, the JAR and the Java sources must be in the same directory. You can apply your programming skills to increase flexibility, just add a fully qualify the location to the JAR.
Note: The java command must be on your path!
Linux: java -jar ${HOME}/lib/patrodyne-scripting-javabang-X.X.X.jar $* Windows: java -jar %HOME%\lib\patrodyne-scripting-javabang-X.X.X.jar %*
By specifying the JAR with a fully qualified path, you can run a Java source file from the current working directory. A source file, say HelloWorld.java must contain the usual 'public static void main(String[] args)' method before for your program will do anything useful. When a main method is found, the arguments after the file name are passed into your program, as you would expect.
Here is an example of HelloWorld.java:
import javax.script.*; class HelloWorld { private static ScriptContext ctx; public static void setScriptContext(ScriptContext ctx) { this.ctx = ctx; } public static void main(String[] args) { System.out.println("Hello World!"); for (int argno=0; argno < args.length; ++argno) System.out.println("\t"+argno+": "+args[argno]); } }
When this example is evaluated as a JSR-223 script by our JAR, the ScriptContext is set prior to execution of the main method. The script context can contain runtime objects as provided by the script engine. In fact, in direct mode, the context will always contain:
System properties can be used to change the default location to search for additional source files, classes and jars:
The second way to use our Script Engine for Java is to include it in the class path of a JSR-223 enabled application. An excellent example of such an application is Patrodyne's TransformIO.
Metadata:
To run Java programs from the command line,
#!/bin/sh # Patrodyne's Scripting Engine for Java java -Dorg.patrodyne.scripting.java.classpath="." \ -jar ~/lib/patrodyne-scripting-javabang-X.X.X.jar $* # vi:set tabstop=4 hardtabs=4 shiftwidth=4: