javax.script Code Samples
- How do I access Java object from a script?
- How do I create a ScriptEngine for JavaScript?
- How do I call a specific function of a script?
- How do I import Java package in script?
- How do I get a ScriptEngine by language name and version?
- How do I evaluate or execute a script file?
- How do I evaluate a simple script?
- How do I modified Java object in script?
- How do I get ScriptEngine by engine name?
- How do I get the supported scripting engine?
Page of 1 |
Prev
|
Next
How do I import Java package in script?
Here you can see how to import a Java class so that you can use the class, creates an instance of
it in the scripting environment. We want to print out the current date on the console. For this we
need to import the Date class that's packaged under the java.util package.
In the script we can import the java.util package using the following script
importPackage(java.util).
This program prints the following line:
Today is Fri Sep 11 2009 17:03:02 GMT+0800 (CST)
