6

我正在通过嵌入式 Jetty 服务器运行我的 Ktor Web 应用程序。该应用程序在 IDE 中运行良好。但是,一旦我用 shadowJar 打包并运行生成的 fat jar,Jetty 服务器就会遇到 NoClassDefFoundError。我相信 NoClassDefFoundError 是由 ExceptionInInitializerError 引起的,这是由于 PreEncodedHttpField 内部的 Jetty 静态初始化内部的 ArrayIndexOutOfBoundsException 引起的。IDE内部怎么不会出现这个错误?从 fat jar 运行 Ktor 应用程序时如何避免它?

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/

我的毕业文件:

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
}
4

1 回答 1

12

将以下内容添加到您的 Gradle 构建脚本中:

import com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
shadowJar {
    transform(ServiceFileTransformer) {
        path = 'META-INF/services'
        include 'org.eclipse.jetty.http.HttpFieldPreEncoder'
    }
}

我最终发现 shadowJar 默认情况下没有将我的“META-INF”文件合并在一起。这是一个问题,因为当 Jetty 服务器启动时,它会引用“META-INF/services/org.eclipse.jetty.http.HttpFieldPreEncoder”来加载正确的 HttpField 编码器。由于我的服务文件没有正确合并,所以只加载了 Http2 编码器。这反过来又导致 JVM 在 Jetty 尝试静态初始化 PreEncodedHttpField 时抛出 java.lang.ExceptionInInitializerError 错误,进而导致 Jetty 的 HttpConnection 中出现 NoClassDefError

我从这里这里找到了提示

于 2018-02-09T04:58:17.030 回答