[stringtemplate-interest] load jarred group definition with a a group loader
Terence Parr
parrt at cs.usfca.edu
Wed Aug 5 12:19:31 PDT 2009
hi. from a jar it probably has to do the getResourceAsStream; not sure
it does...one of the things i plan fixing in v4.0
T
On Aug 5, 2009, at 8:39 AM, Felix Dorner wrote:
> 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
>
>
>
>
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list