Skip to content

Loading template group from STGroupDir in app running on Tomcat 8 fails #293

@Mooninaut

Description

@Mooninaut

StringTemplate version: 4.3.1

I'm migrating a web application from Tomcat 7 to Tomcat 8. It appears something in the class loader behavior has changed between the versions.

My app calls STGroupDir group = new STGroupDir("com/example/app/path/to/templates");

When running on Tomcat 7, after the line root = cl.getResource(dirName); at STGroupDir.java:72 the variable root has the value

jar:file:/path/to/exploded/app/WEB-INF/lib/my-component.jar!/com/example/app/path/to/templates

Running on Tomcat 8, root has the value

jar:file:/path/to/exploded/app/WEB-INF/lib/my-component.jar!/com/example/app/path/to/templates/

My app then calls ST st = group.getInstanceOf("/TemplateGroup/someTemplate"); to load someTemplate from ...path/to/templates/TemplateGroup.stg.

When load() calculates groupFileURL on line STGroupDir.java:128, the value is

jar:file:/path/to/exploded/app/WEB-INF/lib/my-component.jar!/com/example/app/path/to/templates//TemplateName.stg

The double slash prevents it from successfully loading the template group file, and getInstanceOf() returns null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions