Javalin + JTE Hot reload doesn't work
See original GitHub issueI’ve set up things for the hot reload in the my Javalin + JTE based application as follows:
class MyServer{
// ...
private fun createTemplateEngine(): TemplateEngine {
if (isDevSystem()) {
val path = Path.of("src", "main", "jte")
val codeResolver = DirectoryCodeResolver(path)
logger.info("DEVELOPMENT SYSTEM DETECTED. JTE source folder: '${path.toAbsolutePath()}'")
return TemplateEngine.create(codeResolver, ContentType.Html)
} else {
return TemplateEngine.createPrecompiled(ContentType.Html)
}
}
private fun configureJavalin(): Javalin {
JavalinJte.configure(createTemplateEngine())
// ... more stuff here ...
}
// ...
}
But hot reload just doesn’t work. When I change JTE file and referesh page in browser, it just doesn’t change.
I’ve create descendant class from the DirectoryCodeResolver
and overridden interface methods to output stuff to log and forcibly report that file has changed even if it is not.
package mypackage
import gg.jte.resolve.DirectoryCodeResolver
import java.nio.file.Path
import mu.KotlinLogging
class CustomCodeResolver(val path: Path) : DirectoryCodeResolver(path) {
private val logger = KotlinLogging.logger {}
override fun resolve(name: String): String {
val s = super.resolve(name)
logger.info("***JTE*** resolve: $name, size=${s.length}")
return s
}
override fun hasChanged(name: String): Boolean {
val changed = super.hasChanged(name)
logger.info("***JTE*** hasChanged: $name -> $changed")
return true // force "always changed"
}
override fun resolveAllTemplateNames(): List<String> {
logger.info("***JTE*** resolveAllTemplateNames")
return super.resolveAllTemplateNames()
}
}
But still even with forced “always changed” file it still doesn’t work.
According to log outputs, this part works correctly - when I change JTE file and refresh browser, method from DirectoryCodeResolver
reports file as changed, and my custom resolve()
shows different file size.
However, rendering result still as if old version is used. Actually, rendering result corresponds to JTE template content faced on the first rendering - no matter how much times I change page and refresh browser, the page is always as it was first time, before any changes.
Please fix.
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (18 by maintainers)
Top GitHub Comments
Doing it now… One small note: please do
chmod +x mvnw
and commit it. This should be done on Linux or Mac, don’t know how to make git set “executable” bit on the file on Windows, if ever possible.UPDATE Found a way to do it on Windows - read the full story here
TLDR:
Did one more test, and it started to work. The problem was that I’ve previously pointed class directory to the location on the classpath, i.e.
build/resources/main
. After pointing this to another directory, it finally has started to work 🔥🎆🚀:Please reflect this point in the documentation.