casid / jte

Secure and speedy templates for Java and Kotlin.
https://jte.gg
Apache License 2.0
737 stars 54 forks source link

Html Template Output #350

Closed highspeedlowdraghightechlowlife closed 3 months ago

highspeedlowdraghightechlowlife commented 3 months ago

Trying to deploy JTE project using maven. Works fine in IDE but maven keeps throwing errors. Tried to serve the precompiled templates using the documentation on the website. The templates are precompiling fine but they aren't being rendered.

[JettyServerThreadPool-32] ERROR io.javalin.Javalin - Fatal error occurred while servicing http-request java.lang.NoClassDefFoundError: gg/jte/html/HtmlTemplateOutput

Below is a simplified version of my code:

Path targetDirectory = Path.of("/jte"); 
TemplateEngine templateEngine = TemplateEngine.createPrecompiled(targetDirectory, (gg.jte.ContentType.Html));
public static void main(String[] args) {
    Javalin app = Javalin.create(config ->
    {
        config.fileRenderer(new JavalinJte());
    }).start(80);
    app.get("/a", ctx -> ctx.render("hello.jte"));
casid commented 3 months ago

Welcome!

Could you try to add jte explicitly to your pom as dependency? Maybe it is not pulled in transitively via Javalin?

highspeedlowdraghightechlowlife commented 3 months ago

hey, I found a fix, just need to add it to the config.


    Path targetDirectory = Path.of("/jte"); 
    TemplateEngine templateEngine = TemplateEngine.createPrecompiled(targetDirectory, (gg.jte.ContentType.Html));
    public static void main(String[] args)
    {
         Javalin app = Javalin.create(config ->
        {
            config.fileRenderer(
                   new JavalinJte(TemplateEngine.createPrecompiled(ContentType.Html)));
        }).start(7070);