If you are using MAVEN, add this entry to your POM file:
<dependency> <groupId>org.codehaus.janino</groupId> <artifactId>janino</artifactId> <version>2.7.5</version> </dependency>
(Replace '2.7.5' with the very latest version of JANINO.)
If you are not using MAVEN, do the following instead:
- Unzip the distribution file you have downloaded:
$ jar xvf janino-*.zip
- Change to the Janino directory:
$ cd janino-*
You will find the Janino JAR files, the source code ZIP files, the text of the BSD license, and a README file.
- Put "commons-compiler.jar" and "janino.jar" on your class path.
If you're using an IDE like ECLIPSE, you can optionally have "commons-compiler-src.zip" as the source attachment of "commons-compiler.jar", and "janino-src.zip" as the source attachment of "janino.jar". That'll get you tooltip JAVADOC and source level debugging into the JANINO libraries.
Use one of the features, e.g. the "expression evaluator", in your program:
import org.codehaus.janino.*; ExpressionEvaluator ee = new ExpressionEvaluator(); ee.cook("3 + 4"); System.out.println(ee.evaluate(null));
Compile, run, ... be happy!
The ShippingCost class demonstrates how easy it is to use Janino as an expression evaluator.
The ExpressionDemo class implements a command line-based test environment for the expression evaluator.
The ScriptDemo class implements a command line-based test environment for the script evaluator.
The ClassBodyDemo class implements a command line-based test environment for the class body evaluator.
The DeclarationCounter class implements a command-line utility that counts class, interface, field and local variable declarations in a set of JavaTM source files.