2012-04-06 48 views
0

我寫了一個位於/ src文件夾中的示例java文件。如何使用StringTemplate導入目錄?

public class Main { 
    public static void main(String[] args){ 
    STGroupFile StgFile=new STGroupFile("template.stg"); 
    StgFile.delimiterStartChar = '$'; 
    StgFile.delimiterStopChar = '$'; 
    ST webtemp=StgFile.getInstanceOf("test"); 
    webtemp.add("x","whyyy"); 
    System.out.println(webtemp.render()); 
    } 
} 

而且我有一個位於/ src文件夾也

import "headers/header.stg" 
test(x) ::= << $included(x)$ >> 

和位於/ src目錄/頭文件夾中的文件header.stg文件template.stg。

included(x) ::= << headers[$x$] >> 

結果顯然是

headers[whyyy] 

,但如果我嘗試導入整個頭目錄生成類似的template.stg:

import "headers" 
    test(x) ::= << $included(x)$ >> 
  • 所包含的子模板不能被使用...

我使用的StringTemplate的版本是最新的4.0.5,並根據鏈接http://www.antlr.org/wiki/display/ST4/Differences+between+v3+and+v4導入目錄是允許的..我甚至使用/之前和/或之後/ - 相對/絕對路徑,它不起作用: (請幫忙嗎?謝謝:)

回答

3

你試過$header/included(x)$

+0

不 - 我會嘗試 - 但後來 - 因爲我從我的項目中刪除了一段時間的StringTemplate。謝謝 – 2012-05-09 19:13:11

+0

這花了幾年時間 - 對此感到遺憾 - 我已經採用了不同的技術,你可以想像,但那個答案回來了:) – 2014-10-27 15:38:33