Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import fails when template group is loaded using a container classloader #191

Closed
lkrylov opened this issue Sep 6, 2017 · 1 comment · Fixed by #207
Closed

import fails when template group is loaded using a container classloader #191

lkrylov opened this issue Sep 6, 2017 · 1 comment · Fixed by #207
Milestone

Comments

@lkrylov
Copy link

lkrylov commented Sep 6, 2017

Stringtemplate fails to load an included resource in application containers with custom class loaders using import statement in the STG file:

import "org/foo/templates/g.stg"

The particular framework I encountered the issue with was Spring Boot

The underlying cause is that the Misc.urlExists(URL url) method creates a new URLClassLoader() instance and uses the findResource method to check for imported resource. This does not work with
the URLs generated by org.springframework.boot.loader.LaunchedURLClassLoader.

I'm attaching a patch to simplify the Misc.urlExists implementation. Mostly it's a revert of the changes made to address #43 and include an alternative workaround for the JRE bug that causes #43. The tests introduced as a part of #43 still pass with the proposed patch.

patch.txt

@drealeed
Copy link
Contributor

we're having the same problem. I have a spring boot jar that includes a dependency jar which includes the templates. The "import HTMLShared.stg" statement in the templates is failing in Misc.urlExists, even though it does exist; a call to

Thread.currentThread().getContextClassLoader().getResource("full jar path/HTMLShared.stg")

in Misc.urlExists() does return the file.

This has been open for over a year; are there any plans to merge the change, or deploy an update of ST4?

drealeed pushed a commit to drealeed/stringtemplate4 that referenced this issue Oct 31, 2018
drealeed pushed a commit to drealeed/stringtemplate4 that referenced this issue Oct 31, 2018
@parrt parrt closed this as completed in #207 Nov 6, 2018
@parrt parrt added this to the 4.0.9 milestone Nov 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants