我想通過groovy.text.StreamingTemplateEngine(Groovy v2.4.7)處理一個非常簡單的模板。這裏是模板文件的全部內容:Groovy模板解析錯誤:未知類型:IMPORT
<% import org.yaml.snakeyaml.Yaml %>
我知道這不會產生任何輸出。我只是想讓導入工作。
我得到這個錯誤:
Caught: groovy.text.TemplateParseException: Template parse error 'Unknown type: IMPORT at line: 1 column: 146. File: StreamingTemplateScript1.groovy ' at line 1, column 4
--> 1: <% import org.yaml.snakeyaml.Yaml %>
這裏是在做加工的Groovy代碼:
#!/usr/bin/env groovy
def engine = new groovy.text.StreamingTemplateEngine()
def tmplt
if (args.length == 1) {
tmplt = engine.createTemplate(new File(args[0])).make()
}
else {
tmplt = engine.createTemplate(new BufferedReader(new InputStreamReader(System.in))).make()
}
println tmplt.toString()
從我瞭解的Groovy模板,包括在常規腳本程序導入該模板將無法工作(也嘗試過)。我見過其他人(顯然)成功地做了我想要做的事情。
我在做什麼錯?
請注意,我在grails之外進行此操作。