[stringtemplate-interest] loading via classpath

Terence Parr parrt at antlr.org
Fri Feb 4 11:57:29 PST 2011


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


More information about the stringtemplate-interest mailing list