Closed lkrylov closed 6 years ago
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?
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 anew URLClassLoader()
instance and uses thefindResource
method to check for imported resource. This does not work with the URLs generated byorg.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