Skip to content

Cannot access DTO class in compiled JTE template when rendering dynamic templates from Database #487

@Jannaaa5

Description

@Jannaaa5

I’m trying to render dynamic templates stored in a database using JTE in a Kotlin project. I’m using a setup similar to the examples in issue #451 and issue #170

I can successfully load and compile templates on-demand, but when a template references a Kotlin DTO or data class (e.g., DonationEmail), I get a ClassNotFoundException or similar errors. It seems the compiled template cannot find the class from my project when running in a self-contained jar.

Steps to reproduce:

  1. Store a template in the database referencing a Kotlin DTO, e.g.:
  @param  com.example.demo.dto.DonationEmailDto donation
  <p>Hello ${donation.name}</p>
  1. Load the template dynamically using DatabaseCodeResolver or a similar setup.
  2. Render it with a DTO instance:
templateEngine.render(templateName, DonationEmail("John"), output)
  1. Observe the class not found error.

Expected behavior:
The dynamic template should render correctly using the provided Kotlin DTO without errors.

Environment:

  • JTE version: 3.2.1
  • Kotlin version: 2.2.20
  • JDK: 21
  • Running as: self-contained fat jar / Spring Boot application

Question:
Is there a recommended way to make dynamic templates compiled at runtime recognize Kotlin DTO classes when running from a self-contained jar?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions