casid / jte

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

java.lang.NoClassDefFoundError: gg/jte/CodeResolver #275

Closed ccortes66 closed 9 months ago

ccortes66 commented 11 months ago

Hello, how are you? I was generating the JAR using the configurations from the Javalin documentation, and after generating the JAR, I encountered this error: java.lang.NoClassDefFoundError: gg/jte/CodeResolver

public class Main
{
    private static Boolean isDevSystem = false;
    public static void main(String[] args) throws IOException {
        JavalinJte.init(createTemplateEngine());
        Injector injector = Guice.createInjector(new CDI());

        //csr
        /*
        Javalin restApi = Javalin.create().start(8080);
        new ClienteController(restApi,injector);
        new LoginController(restApi,injector);
        new EmpleadoController(restApi,injector);
        */

        //ssr cliente
        Javalin ssr = Javalin.create().start(8080);
        new CookieController(ssr,injector);
        new SsrClienteController(ssr,injector);

        //ssr empleado
        Javalin ssrEmpleados = Javalin.create().start(8083);
        new CoockieControllerEmpleado(ssrEmpleados,injector);
        new SSrEmpleadoController(ssrEmpleados,injector);

    }

    private static TemplateEngine createTemplateEngine() {
        if (isDevSystem) {
            DirectoryCodeResolver codeResolver = new DirectoryCodeResolver(Path.of("src", "main", "jte"));
            return TemplateEngine.create(codeResolver, ContentType.Html);
        } else {
            return TemplateEngine.createPrecompiled(Path.of("jte-classes"),ContentType.Html);
        }
    }

}

pom.xml


<build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.alura.hotelalura.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>gg.jte</groupId>
                <artifactId>jte-maven-plugin</artifactId>
                <version>3.0.1</version>
                <configuration>
                    <sourceDirectory>${basedir}/src/main/jte</sourceDirectory>
                    <targetDirectory>${basedir}/jte-classes</targetDirectory>
                    <contentType>Html</contentType>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>precompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

I would greatly appreciate your response.

casid commented 11 months ago

Hi, can you share a sample project, that demonstrates the problem?

casid commented 11 months ago

Maybe this is the same problem as #280?

ccortes66 commented 11 months ago

Hi, following the thread on GitHub, I was conducting tests, changing the JTE version to the latest one and switching from hot reloading to precompile from VSCode templateEngine. It works for both cases. The error appears when I perform the build in Maven, and the error message is still the same: java.lang.NoClassDefFoundError: gg/jte/CodeResolver.

private static Boolean isDevMode = false; 
    public static void main(String[] args) throws IOException {

        Injector injector = Guice.createInjector(new CDI());
        JavalinJte.init(templateEngine());

        //csr
        /*
        Javalin restApi = Javalin.create().start(8080);
        new ClienteController(restApi,injector);
        new LoginController(restApi,injector);
        new EmpleadoController(restApi,injector);
        */

        //ssr cliente
        Javalin ssr = Javalin.create().start(8080);
        new CookieController(ssr,injector);
        new SsrClienteController(ssr,injector);

        //ssr empleado
        Javalin ssrEmpleados = Javalin.create().start(8083);
        new CoockieControllerEmpleado(ssrEmpleados,injector);
        new SSrEmpleadoController(ssrEmpleados,injector);

    }

    private static TemplateEngine templateEngine()
    {  
       if(isDevMode)
       {
         DirectoryCodeResolver resolver = new DirectoryCodeResolver(Paths.get("src/main/jte"));
         return TemplateEngine.create(resolver,ContentType.Html);
       }

       return TemplateEngine.createPrecompiled(ContentType.Html);
    }

pom.xml


<build>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <release>17</release>
                </configuration>
            </plugin>

            <plugin>
                <groupId>gg.jte</groupId>
                <artifactId>jte-maven-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <sourceDirectory>${basedir}/src/main/jte</sourceDirectory> 
                    <contentType>Html</contentType>
                </configuration>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.alura.hotelalura.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

        </plugins>
    </build>
casid commented 11 months ago

Where do you get the error message, when the maven build is running, or when you start the application that was built via maven? Can you please post the stack trace you get?