I am using IntelliJ IDE where I created a maven project to build a website. I am trying to use Javalin as it is a lightweight framework to use. As per the documentation of Javalin, my pom.xml files is:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>Web-App</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>3.13.6</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
</project>
And under src/main/java, I created a HelloWorld.java to run my webapp. The code is:
import io.javalin.Javalin;
public class HelloWorld {
public static void main(String[] args) {
Javalin app = Javalin.create().start(7000);
app.get("/", ctx -> ctx.result("Hello World"));
}
}
When I run, I get a error like this:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/NoWhenBranchMatchedException
at io.javalin.core.JavalinConfig$Inner.<init>(JavalinConfig.java:73)
at io.javalin.core.JavalinConfig.<init>(JavalinConfig.java:63)
at io.javalin.Javalin.<init>(Javalin.java:52)
at io.javalin.Javalin.create(Javalin.java:88)
at io.javalin.Javalin.create(Javalin.java:76)
at HelloWorld.main(HelloWorld.java:5)
Caused by: java.lang.ClassNotFoundException: kotlin.NoWhenBranchMatchedException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 6 more
Under this circumstances. what could have been my error behind this?
Thanks in advance.
You are missing a logging implementation. I recommend you use this "javalin-bundle" dependency:
It includes some extra libraries, including logging libraries, which are missing if you only use
<artifactId>javalin</artifactId>
.(You also get Jackson, which is used by Javalin behind the scenes to handle JSON rsources - for example
ctx.json(obj)
.)You don't have to use the bundle - you can provide your own logging implementation.