I have a legacy Ruby command line tool that uses (user supplied) ERB templates to format data. I am required to rewrite this tool in Java but I need to avoid having everyone rewrite their ERB templates in a differ开发者_运维百科ent template language.
I think I can do this with embedded JRuby but I have never used it.
Are there any good examples or reference for using ERB from Java apps?
Here you can see at listing 6 how to call ruby from java with jruby.
And to use ERB is very easy :D
require 'erb'
# `binding` returns all variables declared in
# this scope, so they can be used in templates
#
ERB.new(File.read('file/path')).result(binding)
精彩评论