You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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
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 withthe 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
The text was updated successfully, but these errors were encountered: