Java Scripting (JSR223) = Bean/Script Shells for templating?
I have not yet used any "java scripting" (JSR223)
and my question is related to linux (and windows).
Is there an easy way (after installing the scripting language and java) to do the following:
- Run a Script (in the respective language) that imports a template (=a file with placeholders/variables).
- That furthermore imports (read from filesystem) a config file with key=value pairs (java properties file)
- And fills in the placeholder with the key-value pairs.
- And writes t开发者_开发知识库he "merged" content into a file on the filesystem...
(This script should be easily be callable like "java scriptingenvironment scriptname myparameters")
Is this easily possible and/or have you done this before? And do you even know any links where this has been described/done before?
Thank you very much!!!!
Markus
Yes, you can achieve your goal by using a plain Java template engine such as Apache Velocity or StringTemplate and standard filesystem and properties operations. No need to use any java scripting (per JSR223) as you mention.
Application objects can be bound as global variables in scripts via
ScriptEngine.put(String name, Object value);
You can do variable substitution as described in answers to this Stack Overflow question or use some Spring facility whose name escapes me at the moment.
This comes very close: https://developer.mozilla.org/en/Rhino_Shell
精彩评论