question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Javalin + JTE Hot reload doesn't work

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

3reactions
IvanPizhenkocommented, Feb 27, 2021

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:

# Run in the git-bash on Windows:
git update-index --chmod=+x 'name-of-shell-script'
git commit -m "....."
2reactions
IvanPizhenkocommented, Feb 27, 2021

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 🔥🎆🚀:

      return TemplateEngine.create(codeResolver, Path.of("build", "jte-classes-dev-hot-reload"), ContentType.Html)

Please reflect this point in the documentation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rendering jte templates in Javalin
jte supports hot reloading of templates out of the box \o/ ... Let's try to call a method that does not exist and...
Read more >
A small economy & stock viewer project created with Javalin ...
I have been working on a compile time (to Java) handlebars subset but just can't get the time to finish it. The other...
Read more >
Hot Reloading is Not Working in Jhipster - Stack Overflow
Hot Relod doesnt work on java. If you change the code in your Spring Application, you need to run your gradle again.
Read more >
Meet the FGM-148 Javelin Missile uses to Destroy Enemy Tanks
The world's premier shoulder-fired anti-armor system, Javelin, takes the fight to the enemy. The Javelin automatically orients itself at the ...
Read more >
FGM-148 Javelin - Military.com
Manufacturer: Raytheon. Service: US Army, US Marine Corps. Range: 2,000 meters. Warhead: High explosive anti-tank. The JAVELIN is a manportable, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found