[stringtemplate-interest] load jarred group definition with a a group loader
Felix Dorner
felix_do at web.de
Wed Aug 5 08:39:36 PDT 2009
Hi,
java version ;-) I have this structure:
com/abcd/MyCodeGenerator.java
com/abcd/templates/agroup.stg
To load this group from within MyCodeGenerator:
private static String getTemplateBase() {
return MyCodeGenerator.class.getPackage().getName().replace(".", "/") + "/templates/";
}
static {
StringTemplateGroup.registerGroupLoader(new CommonGroupLoader(getTemplateBase(), null));
}
and then:
...
StringTempleteGroup.loadGroup("agroup", DefaultTemplateLexer.class, null);
...
This works well when the whole structure is unpackaged. But now I add all this into a JAR, and it doesn't seem to work anymore, I get 'no such template group or so'.
Does this CommonGroupLoader support loading templates from within a JAR, or would I have to write my own?
I also think that I don't need a grouploader at all, because the group is on its own, no supergroups/interfaces.
So I could just do an ordinary:
getClass.getResourceAsStream("templates/agroup.stg") and use one of the StringTemplateGroup constructors I guess?
On the other hand maybe its cool to leave the templates unpackaged so I can hack around without repackaging... hmmmm.
Thanks for help,
Felix
More information about the stringtemplate-interest
mailing list