开发者

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:

  1. Run a Script (in the respective language) that imports a template (=a file with placeholders/variables).
  2. That furthermore imports (read from filesystem) a config file with key=value pairs (java properties file)
  3. And fills in the placeholder with the key-value pairs.
  4. 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜