[stringtemplate-interest] loading via classpath

Collin Fagan collin.fagan at gmail.com
Fri Feb 4 12:06:57 PST 2011


Is this isn't from a static method, right? I've never had luck with
Thread.currentThread().getContextClassLoader().

You could try

new Object().getClass().getClassLoader().

Collin


On Fri, Feb 4, 2011 at 1:57 PM, Terence Parr <parrt at antlr.org> wrote:

> yo, this doesn't see to work:
>
>             File f = new File(fileName);
>            if ( f.exists() ) {
>                url = f.toURI().toURL();
>            }
>            else { // try in classpath
>                ClassLoader cl =
> Thread.currentThread().getContextClassLoader();
>                url = cl.getResource(fileName);
>                if ( url==null ) {
>                    cl = this.getClass().getClassLoader();
>                    url = cl.getResource(fileName);
>                }
>                if ( url==null ) {
>                    throw new IllegalArgumentException("No such group file:
> "+
>                                                       fileName);
>                }
>            }
>        }
>
> trying Oliver's code to load a template via
>
>        static STGroup test = new
> STGroupFile("org/stringtemplate/v4/benchmark/email.stg"); // tried with and
> w/o leading '/'
>
> won't find the file. ideas?
>
> Ter
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110204/ebc0c959/attachment.html 


More information about the stringtemplate-interest mailing list