I am running my Ktor web app via an embedded Jetty server. The app works just fine inside the IDE. However, once I package it up with shadowJar and run the resulting fat jar, the Jetty server runs into a NoClassDefFoundError. I believe the NoClassDefFoundError is caused by an ExceptionInInitializerError that is occurring because of an ArrayIndexOutOfBoundsException inside of Jetty's static intialization inside of PreEncodedHttpField. How is it that this error doesn't occur inside the IDE? How can I avoid it when running the Ktor app from the fat jar?
02-06-2018 00:27:59.093 [qtp859617558-17] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpConnection
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:126)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
02-06-2018 00:27:59.093 [qtp859617558-24] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpConnection
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
02-06-2018 00:27:59.099 [qtp859617558-26] DEBUG org.eclipse.jetty.io.IdleTimeout - SocketChannelEndPoint@2d8b0948{/0:0:0:0:0:0:0:1:50406<->/0:0:0:0:0:0:0:1:9000,OPEN,fill=-,flush=-,to=10/30000}{io=0/0,kio=0,kro=0}-><null> idle timeout check, elapsed: 6 ms, remaining: 29994 ms
02-06-2018 00:27:59.099 [qtp859617558-17] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpConnection
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:126)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
02-06-2018 00:27:59.099 [qtp859617558-24] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpConnection
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
02-06-2018 00:27:59.099 [qtp859617558-26] DEBUG o.eclipse.jetty.io.AbstractEndPoint - onOpen SocketChannelEndPoint@2d8b0948{/0:0:0:0:0:0:0:1:50406<->/0:0:0:0:0:0:0:1:9000,OPEN,fill=-,flush=-,to=15/30000}{io=0/0,kio=0,kro=0}-><null>
02-06-2018 00:27:59.099 [qtp859617558-17] DEBUG o.e.j.u.t.Invocable$InvocableExecutor - org.eclipse.jetty.util.thread.Invocable$InvocableExecutor@4dfc073a invoked org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@543935e4
02-06-2018 00:27:59.099 [qtp859617558-24] DEBUG o.e.j.util.thread.QueuedThreadPool - ran org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@5689f60
02-06-2018 00:27:59.099 [qtp859617558-17] DEBUG o.e.j.u.t.strategy.EatWhatYouKill - EatWhatYouKill@707b1a44/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@7132a9dc/PRODUCING/1/1 produce exit
02-06-2018 00:27:59.099 [qtp859617558-26] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpConnection
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
02-06-2018 00:27:59.099 [qtp859617558-17] DEBUG o.e.j.util.thread.QueuedThreadPool - ran org.eclipse.jetty.io.ManagedSelector$$Lambda$26/86506638@2c7106d9
02-06-2018 00:27:59.100 [qtp859617558-26] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpConnection
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
02-06-2018 00:27:59.100 [qtp859617558-26] DEBUG o.e.j.util.thread.QueuedThreadPool - ran org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@5ce56a5a
02-06-2018 00:27:59.093 [qtp859617558-20] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpConnection
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
02-06-2018 00:27:59.095 [qtp859617558-22] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.ExceptionInInitializerError: null
at org.eclipse.jetty.server.HttpConnection.<clinit>(HttpConnection.java:54)
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at org.eclipse.jetty.http.PreEncodedHttpField.<clinit>(PreEncodedHttpField.java:71)
... 9 common frames omitted
02-06-2018 00:27:59.094 [qtp859617558-23] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpConnection
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
02-06-2018 00:27:59.102 [qtp859617558-23] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpConnection
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
02-06-2018 00:27:59.102 [qtp859617558-23] DEBUG o.e.j.util.thread.QueuedThreadPool - ran org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@752bc090
02-06-2018 00:27:59.102 [qtp859617558-20] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpConnection
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
02-06-2018 00:27:59.102 [qtp859617558-20] DEBUG o.e.j.util.thread.QueuedThreadPool - ran org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@1985be4c
02-06-2018 00:27:59.103 [qtp859617558-22] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.ExceptionInInitializerError: null
at org.eclipse.jetty.server.HttpConnection.<clinit>(HttpConnection.java:54)
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at org.eclipse.jetty.http.PreEncodedHttpField.<clinit>(PreEncodedHttpField.java:71)
... 9 common frames omitted
02-06-2018 00:27:59.103 [qtp859617558-22] DEBUG o.e.j.util.thread.QueuedThreadPool - ran org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@3416caab
02-06-2018 00:27:59.103 [qtp859617558-18-acceptor-0@178f268a-ServerConnector@cfbc8e8{HTTP/1.1,[http/1.1, h2c]}{0.0.0.0:9000}] DEBUG org.eclipse.jetty.io.ManagedSelector - Queued change org.eclipse.jetty.io.ManagedSelector$Accept@6cf5cd13 on org.eclipse.jetty.io.ManagedSelector@440e3ce6 id=0 keys=1 selected=0
02-06-2018 00:27:59.108 [qtp859617558-16] DEBUG org.eclipse.jetty.io.ManagedSelector - Selector loop woken up from select, 0/0 selected
02-06-2018 00:27:59.108 [qtp859617558-16] DEBUG org.eclipse.jetty.io.ManagedSelector - Running action org.eclipse.jetty.io.ManagedSelector$Accept@6cf5cd13
02-06-2018 00:27:59.108 [qtp859617558-16] DEBUG org.eclipse.jetty.io.ManagedSelector - Queued change org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@44ae85a2 on org.eclipse.jetty.io.ManagedSelector@440e3ce6 id=0 keys=1 selected=0
02-06-2018 00:27:59.108 [qtp859617558-16] DEBUG o.e.j.u.t.strategy.EatWhatYouKill - EatWhatYouKill@3e67f5f2/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@fd53053/PRODUCING/1/1->IDLE/0/1 EPC! org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@44ae85a2
02-06-2018 00:27:59.109 [qtp859617558-19] DEBUG o.e.j.u.t.strategy.EatWhatYouKill - EatWhatYouKill@3e67f5f2/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@fd53053/PRODUCING/0/1 produce non-blocking
02-06-2018 00:27:59.109 [qtp859617558-19] DEBUG org.eclipse.jetty.io.ManagedSelector - Selector loop waiting on select
02-06-2018 00:27:59.109 [qtp859617558-16] DEBUG o.e.j.util.thread.QueuedThreadPool - queue EatWhatYouKill@3e67f5f2/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@fd53053/PRODUCING/0/1
02-06-2018 00:27:59.109 [qtp859617558-16] DEBUG o.e.j.u.t.Invocable$InvocableExecutor - org.eclipse.jetty.util.thread.Invocable$InvocableExecutor@5ba4a467 invoke org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@44ae85a2
02-06-2018 00:27:59.109 [qtp859617558-16] DEBUG org.eclipse.jetty.io.IdleTimeout - SocketChannelEndPoint@56d0b70c{/0:0:0:0:0:0:0:1:50414<->/0:0:0:0:0:0:0:1:9000,OPEN,fill=-,flush=-,to=0/30000}{io=0/0,kio=0,kro=0}-><null> idle timeout check, elapsed: 0 ms, remaining: 30000 ms
02-06-2018 00:27:59.110 [qtp859617558-16] DEBUG o.eclipse.jetty.io.AbstractEndPoint - onOpen SocketChannelEndPoint@56d0b70c{/0:0:0:0:0:0:0:1:50414<->/0:0:0:0:0:0:0:1:9000,OPEN,fill=-,flush=-,to=0/30000}{io=0/0,kio=0,kro=0}-><null>
02-06-2018 00:27:59.110 [qtp859617558-16] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpConnection
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:126)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
02-06-2018 00:27:59.113 [qtp859617558-26] DEBUG o.e.j.util.thread.QueuedThreadPool - run EatWhatYouKill@3e67f5f2/org.eclipse.jetty.io.Man053/PRODUCING/0/1
02-06-2018 00:27:59.113 [qtp859617558-26] DEBUG o.e.j.u.t.strategy.EatWhatYouKill - EatWhatYouKill@3e67f5f2/org.eclipse.jetty.io.ManagedSRODUCING/0/1 run
02-06-2018 00:27:59.116 [qtp859617558-16] DEBUG org.eclipse.jetty.io.ManagedSelector -
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.jetty.server.HttpConnection
at org.eclipse.jetty.server.HttpConnectionFactory.newConnection(HttpConnectionFactory.java:85)
at org.eclipse.jetty.server.ServerConnector$ServerConnectorManager.newConnection(ServerConnector.java:482)
at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:424)
at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:61)
at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:603)
at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:126)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)
02-06-2018 00:27:59.119 [qtp859617558-16] DEBUG o.e.j.u.t.Invocable$InvocableExecutor - org.eclipse.jetty.util.thread.Invocable$Invocablepse.jetty.io.ManagedSelector$CreateEndPoint@44ae85a2
02-06-2018 00:27:59.119 [qtp859617558-16] DEBUG o.e.j.u.t.strategy.EatWhatYouKill - EatWhatYouKill@3e67f5f2/org.eclipse.jetty.io.ManagedSRODUCING/1/1 produce exit
02-06-2018 00:27:59.119 [qtp859617558-16] DEBUG o.e.j.util.thread.QueuedThreadPool - ran org.eclipse.jetty.io.ManagedSelector$$Lambda$26/
My gradle file:
buildscript {
ext.kotlin_version = '1.2.21'
ext.ktorVersion = '0.9.1'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.github.jengelman.gradle.plugins:shadow:2.0.2"
}
}
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = 'routing.MainKt'
shadowJar {
baseName = 'baseName'
classifier = null
version = null
}
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
kotlin {
experimental {
coroutines "enable"
}
}
repositories {
mavenCentral()
jcenter()
maven { url "https://dl.bintray.com/kotlin/kotlinx" }
maven { url "https://dl.bintray.com/kotlin/ktor" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
// Core Kotlin libs
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
// Core Ktor libs
def withoutKotlin = {
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk7'
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-reflect'
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jre8'
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jre7'
}
implementation "io.ktor:ktor-server-core:$ktorVersion", withoutKotlin
implementation "io.ktor:ktor-server-netty:$ktorVersion", withoutKotlin
implementation "io.ktor:ktor-freemarker:$ktorVersion", withoutKotlin
implementation "io.ktor:ktor-locations:$ktorVersion", withoutKotlin
.... More dependencies
}
Add the following to your Gradle build script:
import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
shadowJar {
transform(ServiceFileTransformer) {
path = 'META-INF/services'
include 'org.eclipse.jetty.http.HttpFieldPreEncoder'
}
}
I ending up finding out that shadowJar was not by-default merging my "META-INF" files together. This was a problem because when the Jetty server starts up, it references "META-INF/services/org.eclipse.jetty.http.HttpFieldPreEncoder" to load the correct HttpField encoders. Since my service files were not being merged correctly, only the Http2 encoder was loaded. This in turn caused the JVM to throw an java.lang.ExceptionInInitializerError error while Jetty was trying to statically initialize PreEncodedHttpField, which in turn led to a NoClassDefError in Jetty's HttpConnection
I found hints from here and here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With