Search code examples
google-app-enginejinjava

JinJava Uncaught exception from servlet due to logger


Trying to use JinJava on App-Engine, I get the following exception

Uncaught exception from servlet
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.hubspot.jinjava.util.Logging.<clinit>(Logging.java:23)
    at com.hubspot.jinjava.lib.SimpleLibrary.register(SimpleLibrary.java:59)
    at com.hubspot.jinjava.lib.SimpleLibrary.registerClasses(SimpleLibrary.java:49)
    at com.hubspot.jinjava.lib.exptest.ExpTestLibrary.registerDefaults(ExpTestLibrary.java:13)
    at com.hubspot.jinjava.lib.SimpleLibrary.<init>(SimpleLibrary.java:34)
    at com.hubspot.jinjava.lib.exptest.ExpTestLibrary.<init>(ExpTestLibrary.java:8)
    at com.hubspot.jinjava.interpret.Context.<init>(Context.java:54)
    at com.hubspot.jinjava.interpret.Context.<init>(Context.java:47)
    at com.hubspot.jinjava.Jinjava.<init>(Jinjava.java:81)
    at com.hubspot.jinjava.Jinjava.<init>(Jinjava.java:71)

My appengin-web.xml file already comes with this

<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
        <!--I add these below -->
        <property name="java.util.logging.config.file"
                  value="WEB-INF/java-util-logging.properties"/>
        <property name="os.version" value="1.0.GAE whatever"/>
        <property name="os.arch" value="GAE whatever"/>
...

but it makes no difference if I comment out those lines


Solution

  • It looks like jinjava uses slf4j for logging and it's unable to find the classes in your classpath. This type of error usually means, that you're missing dependency jars.

    When logging through slf4j on AppEngine your need two dependencies:

    With maven the dependencies could look like this

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.7.8</version>
        </dependency>
    

    But you can add slf4j-api and slf4j-jdk14 manually. Simply download them from your favorite jar-source and add them to your build path.